Skip to content

Commit

Permalink
Fixed client general request bug. Fixed upload tournament API misalig…
Browse files Browse the repository at this point in the history
…nment
  • Loading branch information
TylerBloom committed Dec 4, 2023
1 parent 51bd7b3 commit b9d42a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion squire_sdk/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const IMPORT_TOURN_ENDPOINT: Url<0> = Url::from("/");

impl PostRequest<0> for TournamentManager {
const ROUTE: Url<0> = extend!(TOURNAMENTS_ROUTE, IMPORT_TOURN_ENDPOINT);
type Response = bool;
type Response = ();
}

/* ---------- Account Routes ---------- */
Expand Down
2 changes: 1 addition & 1 deletion squire_sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl SquireClient {
return BackendImportStatus::NotFound;
};

if self.post_request(tourn, []).output().await.unwrap() {
if self.post_request(tourn, []).output().await.is_ok() {
BackendImportStatus::Success
} else {
BackendImportStatus::AlreadyImported
Expand Down
12 changes: 10 additions & 2 deletions squire_sdk/src/client/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
use crate::{

Check failure on line 13 in squire_sdk/src/client/network.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, ubuntu-latest)

Diff in /home/runner/work/SquireCore/SquireCore/squire_sdk/src/client/network.rs
actor::*,
api::{Credentials, GetRequest, GuestSession, Login, PostRequest, SessionToken},
compat::{NetworkResponse, Websocket, WebsocketMessage},
compat::{NetworkResponse, Websocket, WebsocketMessage, log},
};

#[cfg(target_family = "wasm")]
Expand Down Expand Up @@ -77,7 +77,11 @@ impl ActorState for NetworkState {

async fn process(&mut self, scheduler: &mut Scheduler<Self>, msg: Self::Message) {
match msg {
NetworkCommand::Request(req, send) => {
NetworkCommand::Request(mut req, send) => {
let headers = req.headers_mut();
if let Some((name, header)) = self.token.as_ref().map(SessionToken::as_header) {
let _ = headers.insert(name, header);
}
let fut = self.client.execute(req);
scheduler.process(async move { drop(send.send(NetworkResponse::new(fut.await))) });
}
Expand All @@ -88,14 +92,17 @@ impl ActorState for NetworkState {
// FIXME: Don't assume it was a cred error. Look at the error and
// investigate.
drop(send.send(Err(LoginError::CredentialError)));
log("Request failed...");
return None;
};
let Some(token) = SessionToken::try_from(resp.headers()).ok() else {
drop(send.send(Err(LoginError::ServerError)));
log("Could not construct session token...");
return None;
};
let Some(acc) = resp.json::<SquireAccount>().await.ok() else {
drop(send.send(Err(LoginError::ServerError)));
log("Could not deserialize account...");
return None;
};
drop(send.send(Ok(acc.clone())));
Expand Down Expand Up @@ -184,6 +191,7 @@ impl NetworkState {
.client
.post(format!("{}{}", self.url, B::ROUTE.replace(subs)))
.header(CONTENT_TYPE, "application/json");
log(&format!("{:?}", self.token));
if let Some((name, header)) = self.token.as_ref().map(SessionToken::as_header) {
builder = builder.header(name, header);
}
Expand Down

0 comments on commit b9d42a7

Please sign in to comment.