fix: return auth errors (#451)
This commit is contained in:
parent
a11c4de332
commit
5216ab2bbd
1 changed files with 43 additions and 10 deletions
|
|
@ -18,6 +18,11 @@ use crate::{
|
|||
|
||||
type BoxedSseStream = BoxStream<'static, Result<Sse, SseError>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AuthRequiredError {
|
||||
pub www_authenticate_header: String,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum StreamableHttpError<E: std::error::Error + Send + Sync + 'static> {
|
||||
#[error("SSE error: {0}")]
|
||||
|
|
@ -48,6 +53,8 @@ pub enum StreamableHttpError<E: std::error::Error + Send + Sync + 'static> {
|
|||
#[cfg_attr(docsrs, doc(cfg(feature = "auth")))]
|
||||
#[error("Auth error: {0}")]
|
||||
Auth(#[from] crate::transport::auth::AuthError),
|
||||
#[error("Auth required")]
|
||||
AuthRequired(AuthRequiredError),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Error)]
|
||||
|
|
@ -274,8 +281,7 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
|
|||
responder,
|
||||
message: initialize_request,
|
||||
} = context.recv_from_handler().await?;
|
||||
let _ = responder.send(Ok(()));
|
||||
let (message, session_id) = self
|
||||
let (message, session_id) = match self
|
||||
.client
|
||||
.post_message(
|
||||
config.uri.clone(),
|
||||
|
|
@ -284,12 +290,22 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
|
|||
self.config.auth_header,
|
||||
)
|
||||
.await
|
||||
.map_err(WorkerQuitReason::fatal_context("send initialize request"))?
|
||||
.expect_initialized::<C::Error>()
|
||||
.await
|
||||
.map_err(WorkerQuitReason::fatal_context(
|
||||
"process initialize response",
|
||||
))?;
|
||||
{
|
||||
Ok(res) => {
|
||||
let _ = responder.send(Ok(()));
|
||||
res.expect_initialized::<C::Error>().await.map_err(
|
||||
WorkerQuitReason::fatal_context("process initialize response"),
|
||||
)?
|
||||
}
|
||||
Err(err) => {
|
||||
let msg = format!("{:?}", err);
|
||||
let _ = responder.send(Err(err));
|
||||
return Err(WorkerQuitReason::fatal(
|
||||
StreamableHttpError::TransportChannelClosed,
|
||||
msg,
|
||||
));
|
||||
}
|
||||
};
|
||||
let session_id: Option<Arc<str>> = if let Some(session_id) = session_id {
|
||||
Some(session_id.into())
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue