fix: return error on non-2xx response in stream_generate_content (#3)
Some checks failed
Rust / build (pull_request) Has been cancelled
Some checks failed
Rust / build (pull_request) Has been cancelled
Check response.status() before building the SSE event stream. On non-success status, parse the response body as GenerateContentResponseError when possible (returning Error::VertexError), and fall back to Error::HttpStatus with the status code and raw text. Adds tests for HTTP 400 Vertex error, non-JSON HTTP 500 error, and successful 200 SSE streaming.
This commit is contained in:
@@ -16,6 +16,11 @@ pub enum Error {
|
||||
NoCandidatesError,
|
||||
/// An error occurred while decoding the SSE event stream.
|
||||
EventSourceError(LinesCodecError),
|
||||
/// An HTTP error status was returned by the server.
|
||||
HttpStatus {
|
||||
status: reqwest::StatusCode,
|
||||
body: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
@@ -28,6 +33,7 @@ impl Display for Error {
|
||||
Error::VertexError(e) => write!(f, "Vertex error: {e}"),
|
||||
Error::NoCandidatesError => write!(f, "No candidates returned for the prompt"),
|
||||
Error::EventSourceError(e) => write!(f, "EventSource error: {e}"),
|
||||
Error::HttpStatus { status, body } => write!(f, "HTTP status {status}: {body}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user