pub struct ServerError { /* private fields */ }Expand description
A transport-neutral server error. Display shows the public message
only. Debug shows the log detail as Redacted and replaces the
value of every crate::NEVER_LOG header with a placeholder; a sink
that knows deployment-configured names logs headers through
crate::Redactor instead.
Implementations§
Source§impl ServerError
impl ServerError
Sourcepub fn new(code: Code, public: impl Into<Cow<'static, str>>) -> Self
pub fn new(code: Code, public: impl Into<Cow<'static, str>>) -> Self
An error with code and a client-safe public message.
Sourcepub fn is_transport_admission_required(&self) -> bool
pub fn is_transport_admission_required(&self) -> bool
Whether a transport-identity (ssh or enc) pipeline refused because admission wants a payment or a reservation those transports cannot carry: the ssh binding answers “use mkit+https” for it, rather than a message that reads as a denied write.
Sourcepub fn invalid_argument(public: impl Into<Cow<'static, str>>) -> Self
pub fn invalid_argument(public: impl Into<Cow<'static, str>>) -> Self
Sourcepub fn unauthenticated(public: impl Into<Cow<'static, str>>) -> Self
pub fn unauthenticated(public: impl Into<Cow<'static, str>>) -> Self
Sourcepub fn permission_denied(public: impl Into<Cow<'static, str>>) -> Self
pub fn permission_denied(public: impl Into<Cow<'static, str>>) -> Self
Code::PermissionDenied, with its default HTTP status (403).
Sourcepub fn admission_challenge(challenge: Bytes) -> Self
pub fn admission_challenge(challenge: Bytes) -> Self
An admission challenge (SPEC-TRANSPORT-CONNECT §5.1):
Code::PermissionDenied with HTTP status 402 and exactly one
ADMISSION_CHALLENGE_TYPE detail. challenge is the encoded
AdmissionChallenge message. Challenge headers such as
WWW-Authenticate are added with Self::with_header.
Sourcepub fn repository_not_found() -> Self
pub fn repository_not_found() -> Self
Code::NotFound for a repository that is missing or unreadable
without revealing which (SPEC-WRITE-GRANTS §9.3).
Sourcepub fn failed_precondition(public: impl Into<Cow<'static, str>>) -> Self
pub fn failed_precondition(public: impl Into<Cow<'static, str>>) -> Self
Sourcepub fn resource_exhausted(public: impl Into<Cow<'static, str>>) -> Self
pub fn resource_exhausted(public: impl Into<Cow<'static, str>>) -> Self
Code::ResourceExhausted: a client-attributable cap only (see
Code).
Sourcepub fn aborted_retryable(public: impl Into<Cow<'static, str>>) -> Self
pub fn aborted_retryable(public: impl Into<Cow<'static, str>>) -> Self
Code::Aborted: the same operation is in flight and the client may
retry it unchanged (PRD §5.4 stage 0, in_flight replay records).
Sourcepub fn unimplemented(public: impl Into<Cow<'static, str>>) -> Self
pub fn unimplemented(public: impl Into<Cow<'static, str>>) -> Self
Sourcepub fn internal(public: &'static str, detail: impl Display) -> Self
pub fn internal(public: &'static str, detail: impl Display) -> Self
A backend failure: a fixed public message, with detail kept only
for server-side logs (issue #794).
Sourcepub fn with_http_status(self, status: u16) -> Self
pub fn with_http_status(self, status: u16) -> Self
Set the HTTP status the Connect binding answers with. Only error
statuses (400..=599) are accepted, and 402 only on
Code::PermissionDenied (use Self::admission_challenge). Any
other value fails a debug assertion and is ignored.
Sourcepub fn try_with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Result<Self, InvalidHeader>
pub fn try_with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Result<Self, InvalidHeader>
Add a response header from dynamic input, e.g. a value an admission helper produced.
§Errors
InvalidHeader if the name is not an HTTP token, is reserved
(a request credential, framing, hop-by-hop or cookie header), or the
value holds a control character. self is dropped on error.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Add a response header, e.g. WWW-Authenticate. An invalid or
reserved header is dropped with a warning, so a credential or a
framing header can never be echoed. A reserved name is a
programming error and also fails a debug assertion; a malformed
value never panics. Use Self::try_with_header to handle the
failure instead.
Sourcepub fn with_detail(self, detail: ErrorDetail) -> Self
pub fn with_detail(self, detail: ErrorDetail) -> Self
Attach a typed error detail. An error carries at most one
ADMISSION_CHALLENGE_TYPE detail (checked in debug builds).
Sourcepub fn public_message(&self) -> &str
pub fn public_message(&self) -> &str
The client-safe message.
Sourcepub fn log_detail(&self) -> Option<&str>
pub fn log_detail(&self) -> Option<&str>
The server-side detail, for the log sink only.
Sourcepub fn http_status(&self) -> Option<u16>
pub fn http_status(&self) -> Option<u16>
The HTTP status override, if any.
Sourcepub fn headers(&self) -> &[(String, String)]
pub fn headers(&self) -> &[(String, String)]
Response headers, in insertion order. Values may include receipts
(crate::NEVER_LOG); log them through crate::Redactor.
Sourcepub fn details(&self) -> &[ErrorDetail]
pub fn details(&self) -> &[ErrorDetail]
Typed error details, in insertion order.
Trait Implementations§
Source§impl Clone for ServerError
impl Clone for ServerError
Source§impl Debug for ServerError
impl Debug for ServerError
Source§impl Display for ServerError
impl Display for ServerError
Source§impl Error for ServerError
impl Error for ServerError
1.30.0 · 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<RefWireError> for ServerError
impl From<RefWireError> for ServerError
Source§fn from(err: RefWireError) -> Self
fn from(err: RefWireError) -> Self
The Connect code and message.
Source§impl From<ServerError> for ConnectError
impl From<ServerError> for ConnectError
Source§fn from(err: ServerError) -> Self
fn from(err: ServerError) -> Self
Source§impl From<ServerError> for ResolveFailure
impl From<ServerError> for ResolveFailure
Source§fn from(error: ServerError) -> Self
fn from(error: ServerError) -> Self
Source§impl From<UploadError> for ServerError
impl From<UploadError> for ServerError
Source§fn from(err: UploadError) -> Self
fn from(err: UploadError) -> Self
The Connect code and message.