use thiserror::Error;
use crate::domain::MessageEndpointError;
pub(super) const PREVIEW: usize = 120;
#[derive(Debug, Error)]
pub enum LegacySseError {
#[error("the url {got:?} is not usable: {reason}")]
Url {
got: String,
reason: String,
},
#[error("the {method} request to the peer could not be completed: {error}")]
Io {
method: &'static str,
error: reqwest::Error,
},
#[error("the peer refused the {method} with {status}: {preview}")]
Refused {
method: &'static str,
status: reqwest::StatusCode,
content_type: Option<String>,
preview: String,
},
#[error("the peer answered the stream request with {got:?}, which is not an event stream")]
NotAStream {
got: String,
},
#[error("the first event on a fresh stream was {got:?}, which is not an `endpoint` event")]
FirstEventNotEndpoint {
got: String,
},
#[error("the peer named a message endpoint this client will not use: {reason}")]
Endpoint {
reason: MessageEndpointError,
},
#[error("the stream carried {got:?}, which this client cannot read: {reason}")]
Unreadable {
got: String,
reason: String,
},
}
impl LegacySseError {
pub(crate) const fn endpoint(reason: MessageEndpointError) -> Self {
Self::Endpoint { reason }
}
}