Skip to content

Commit

Permalink
feat: handle error status (#338)
Browse files Browse the repository at this point in the history
* handle non-success status

* fmt
  • Loading branch information
jorgeantonio21 authored Jan 14, 2025
1 parent d385f60 commit 7df38e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions atoma-service/src/handlers/chat_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,17 @@ pub(crate) mod utils {
endpoint: endpoint.to_string(),
}
})?;

if !response.status().is_success() {
return Err(AtomaServiceError::InternalError {
message: format!(
"Inference service returned non-success status code: {}",
response.status()
),
endpoint: endpoint.to_string(),
});
}

response.json::<Value>().await.map_err(|e| {
AtomaServiceError::InternalError {
message: format!(
Expand Down
11 changes: 11 additions & 0 deletions atoma-service/src/handlers/embeddings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ async fn handle_embeddings_response(
message: format!("Error sending request to embeddings service: {}", e),
endpoint: endpoint.to_string(),
})?;

if !response.status().is_success() {
return Err(AtomaServiceError::InternalError {
message: format!(
"Inference service returned non-success status code: {}",
response.status()
),
endpoint: endpoint.to_string(),
});
}

let mut response_body =
response
.json::<Value>()
Expand Down
11 changes: 11 additions & 0 deletions atoma-service/src/handlers/image_generations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ async fn handle_image_generations_response(
message: format!("Error sending request to image generations service: {}", e),
endpoint: endpoint.to_string(),
})?;

if !response.status().is_success() {
return Err(AtomaServiceError::InternalError {
message: format!(
"Inference service returned non-success status code: {}",
response.status()
),
endpoint: endpoint.to_string(),
});
}

let mut response_body =
response
.json::<Value>()
Expand Down

0 comments on commit 7df38e6

Please sign in to comment.