pub struct TransportError { /* private fields */ }Expand description
Why a request got no (complete) response.
Implementations§
Source§impl TransportError
impl TransportError
Sourcepub fn new(kind: TransportErrorKind, message: impl Into<String>) -> Self
pub fn new(kind: TransportErrorKind, message: impl Into<String>) -> Self
Create an error.
Mark the message as written by the transport’s own code, with no
text from a foreign error, the request, or the response in it, so
into_error keeps it as the
authored message.
The same contract as allama::Error::authored: never call it on a
message that embeds an HTTP client’s error text, which can contain
the request URL.
Sourcepub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Self
pub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Self
Attach the underlying error. into_error and
into_stream_error keep it as the portable
error’s source, so a caller can
downcast it (a TLS failure from a DNS one). Its text is printed
wherever the error’s chain is, so attach only errors whose Display
holds no secret, such as a URL with a key in its query.
Sourcepub fn kind(&self) -> TransportErrorKind
pub fn kind(&self) -> TransportErrorKind
What went wrong.
Sourcepub fn into_error(self) -> Error
pub fn into_error(self) -> Error
The portable error for a failure before or while receiving a unary
response: allama::Error::Timeout, allama::Error::InvalidRequest,
or allama::Error::Transport.
The constructor message is an authored
description of the kind. The transport’s own text is
the upstream message: an HTTP
client’s error can contain the request URL, and some APIs put the key
in the query string, so it stays out of the redacted
ErrorLog. A message marked
authored is the constructor message instead.
use allama_http::{TransportError, TransportErrorKind};
let err = TransportError::new(
TransportErrorKind::Connect,
"error sending request for url (https://api.example.com/v1?key=SECRET)",
)
.into_error();
assert_eq!(err.as_log().to_string(), r#"kind=transport message="the request got no response""#);
assert!(err.to_string().contains("api.example.com"));Sourcepub fn into_stream_error(self) -> Error
pub fn into_stream_error(self) -> Error
The portable error for a failure while reading a streamed response,
after it started: allama::Error::Timeout for a timeout (a stream
timeout stays a timeout, so retry policies treat it as one), and a
StreamErrorKind::Transport
stream error, which is retryable, for anything else.
As in into_error, the constructor message is
authored and the transport’s own text is
the upstream message, unless
the message is marked authored.
SseError::into_error maps a failed body
read with it.
use allama::{Error, StreamErrorKind};
use allama_http::{TransportError, TransportErrorKind};
let err = TransportError::new(TransportErrorKind::Body, "connection reset by peer")
.into_stream_error();
assert!(matches!(err, Error::Stream { kind: StreamErrorKind::Transport, .. }));
assert!(err.is_retryable());
assert_eq!(err.upstream_message(), Some("connection reset by peer"));
let err = TransportError::new(TransportErrorKind::Timeout, "idle for 30s").into_stream_error();
assert!(matches!(err, Error::Timeout { .. }));Trait Implementations§
Source§impl Debug for TransportError
impl Debug for TransportError
Source§impl Display for TransportError
impl Display for TransportError
Source§impl Error for TransportError
impl Error for TransportError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<TransportError> for Error
impl From<TransportError> for Error
Source§fn from(err: TransportError) -> Self
fn from(err: TransportError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for TransportError
impl !UnwindSafe for TransportError
impl Freeze for TransportError
impl Send for TransportError
impl Sync for TransportError
impl Unpin for TransportError
impl UnsafeUnpin for TransportError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.