chore: propagate error to client (#1276)

* chore: return error

* chore: log parse json error
This commit is contained in:
Nathan.fooo 2025-03-16 16:54:14 +08:00 committed by GitHub
parent d3338d03b4
commit a36bad83a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -448,7 +448,7 @@ impl Stream for QuestionStream {
},
Some(Err(err)) => {
error!("Error while streaming answer: {:?}", err);
Poll::Pending
Poll::Ready(Some(Err(err)))
},
None => Poll::Ready(None),
}

View file

@ -11,6 +11,7 @@ use serde_json::de::SliceRead;
use serde_json::StreamDeserializer;
use std::error::Error as StdError;
use std::task::{Context, Poll};
use tracing::error;
pub async fn check_response(resp: reqwest::Response) -> Result<(), Error> {
let status_code = resp.status();
@ -106,12 +107,14 @@ where
this.buffer.drain(0..offset);
return Poll::Ready(Some(Ok(value)));
},
Some(Err(err)) if err.is_eof() => {
// Wait for more data if EOF indicates incomplete data
return Poll::Pending;
},
Some(Err(err)) => {
return Poll::Ready(Some(Err(err.into())));
return if err.is_eof() {
// Wait for more data if EOF indicates incomplete data
Poll::Pending
} else {
error!("parse json stream failed: {:?}", err);
Poll::Ready(Some(Err(err.into())))
};
},
None => {
// No complete object is ready, wait for more data