Skip to content

Commit

Permalink
runtimes/core: correctly extract error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed Dec 27, 2024
1 parent c8b7ffe commit d2518cc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion runtimes/core/src/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ impl ServiceRegistry {
Ok((req, resp_schema)) => {
let fut = http_client.execute(req);
match fut.await {
Ok(resp) => resp_schema.extract(resp).await,
Ok(resp) => {
if !resp.status().is_success() {
return Err(extract_error(resp).await);
}
resp_schema.extract(resp).await
}
Err(e) => Err(api::Error::internal(e)),
}
}
Expand Down Expand Up @@ -526,3 +531,12 @@ where
Ok(())
}
}

async fn extract_error(resp: reqwest::Response) -> api::Error {
match resp.bytes().await {
Ok(bytes) => serde_json::from_slice(&bytes).unwrap_or_else(|err| {
api::Error::invalid_argument("unable to parse error response", err)
}),
Err(err) => api::Error::invalid_argument("unable to read response body", err),
}
}

0 comments on commit d2518cc

Please sign in to comment.