Skip to content

Commit d7de2ad

Browse files
authored
Merge pull request #12 from RobGeada/ErrorHandling
Bugfix: Return orchestrator errors transparently back to the user
2 parents 1c2f623 + 0f0f839 commit d7de2ad

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,19 @@ async fn orchestrator_post_request(
157157
url: &str,
158158
) -> Result<OrchestratorResponse, anyhow::Error> {
159159
let client = reqwest::Client::new();
160-
let response = client.post(url).json(&payload).send();
160+
let response = client.post(url).json(&payload).send().await?;
161+
let status = response.status();
162+
let text = response.text().await?;
163+
164+
if !status.is_success() {
165+
// Return the error with the status code and response body
166+
return Err(anyhow::anyhow!(
167+
"Orchestrator returned error status {}: {}",
168+
status,
169+
text
170+
));
171+
}
161172

162-
let json = response.await?.json().await?;
173+
let json: serde_json::Value = serde_json::from_str(&text)?;
163174
Ok(serde_json::from_value(json).expect("unexpected json response from request"))
164175
}

0 commit comments

Comments
 (0)