pub struct ConnectError {
pub code: ErrorCode,
pub message: Option<String>,
pub details: Vec<ErrorDetail>,
/* private fields */
}Expand description
A ConnectRPC error.
Fields§
§code: ErrorCodeThe error code.
message: Option<String>Human-readable error message.
details: Vec<ErrorDetail>Additional error details.
Implementations§
Source§impl ConnectError
impl ConnectError
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self
Create a new error with the given code and message.
Sourcepub fn with_headers(self, headers: HeaderMap) -> Self
pub fn with_headers(self, headers: HeaderMap) -> Self
Add response headers to be included in the error response.
Sourcepub fn with_trailers(self, trailers: HeaderMap) -> Self
pub fn with_trailers(self, trailers: HeaderMap) -> Self
Add response trailers to be included in the error response.
Sourcepub fn response_headers(&self) -> &HeaderMap
pub fn response_headers(&self) -> &HeaderMap
Borrow the response headers. Returns an empty map if none were set.
Sourcepub fn trailers(&self) -> &HeaderMap
pub fn trailers(&self) -> &HeaderMap
Borrow the response trailers. Returns an empty map if none were set.
Sourcepub fn response_headers_mut(&mut self) -> &mut HeaderMap
pub fn response_headers_mut(&mut self) -> &mut HeaderMap
Mutably borrow the response headers, allocating an empty map if none were set.
Sourcepub fn trailers_mut(&mut self) -> &mut HeaderMap
pub fn trailers_mut(&mut self) -> &mut HeaderMap
Mutably borrow the response trailers, allocating an empty map if none were set.
Sourcepub fn set_response_headers(&mut self, headers: HeaderMap)
pub fn set_response_headers(&mut self, headers: HeaderMap)
Replace the response headers. An empty map is stored as None.
Sourcepub fn set_trailers(&mut self, trailers: HeaderMap)
pub fn set_trailers(&mut self, trailers: HeaderMap)
Replace the response trailers. An empty map is stored as None.
Sourcepub fn with_http_status(self, status: StatusCode) -> Self
pub fn with_http_status(self, status: StatusCode) -> Self
Set an HTTP status override for this error.
When set, this overrides the default HTTP status derived from the error code. This is useful for HTTP-level errors like 415 Unsupported Media Type.
Sourcepub fn unsupported_media_type(message: impl Into<String>) -> Self
pub fn unsupported_media_type(message: impl Into<String>) -> Self
Create an error for unsupported media type (HTTP 415).
This is used when the client sends a content type that the server doesn’t support.
Sourcepub fn method_not_allowed(message: impl Into<String>) -> Self
pub fn method_not_allowed(message: impl Into<String>) -> Self
Create an error for method not allowed (HTTP 405).
This is used when the client uses an HTTP method other than POST.
Sourcepub fn invalid_argument(message: impl Into<String>) -> Self
pub fn invalid_argument(message: impl Into<String>) -> Self
Create an invalid argument error.
Sourcepub fn deadline_exceeded(message: impl Into<String>) -> Self
pub fn deadline_exceeded(message: impl Into<String>) -> Self
Create a deadline exceeded error.
Sourcepub fn already_exists(message: impl Into<String>) -> Self
pub fn already_exists(message: impl Into<String>) -> Self
Create an already exists error.
Sourcepub fn permission_denied(message: impl Into<String>) -> Self
pub fn permission_denied(message: impl Into<String>) -> Self
Create a permission denied error.
Sourcepub fn resource_exhausted(message: impl Into<String>) -> Self
pub fn resource_exhausted(message: impl Into<String>) -> Self
Create a resource exhausted error.
Sourcepub fn failed_precondition(message: impl Into<String>) -> Self
pub fn failed_precondition(message: impl Into<String>) -> Self
Create a failed precondition error.
Sourcepub fn out_of_range(message: impl Into<String>) -> Self
pub fn out_of_range(message: impl Into<String>) -> Self
Create an out of range error.
Sourcepub fn unimplemented(message: impl Into<String>) -> Self
pub fn unimplemented(message: impl Into<String>) -> Self
Create an unimplemented error.
Create an unavailable error.
Sourcepub fn unauthenticated(message: impl Into<String>) -> Self
pub fn unauthenticated(message: impl Into<String>) -> Self
Create an unauthenticated error.
Sourcepub fn with_detail(self, detail: ErrorDetail) -> Self
pub fn with_detail(self, detail: ErrorDetail) -> Self
Add an error detail.
Sourcepub fn http_status(&self) -> StatusCode
pub fn http_status(&self) -> StatusCode
Get the HTTP status code for this error.
Returns the HTTP status override if set, otherwise derives it from the error code.
Trait Implementations§
Source§impl Clone for ConnectError
impl Clone for ConnectError
Source§fn clone(&self) -> ConnectError
fn clone(&self) -> ConnectError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConnectError
impl Debug for ConnectError
Source§impl<'de> Deserialize<'de> for ConnectError
impl<'de> Deserialize<'de> for ConnectError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for ConnectError
impl Display for ConnectError
Source§impl Error for ConnectError
impl Error for ConnectError
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<Error> for ConnectError
impl From<Error> for ConnectError
Source§impl From<Error> for ConnectError
Lets Response::try_with_header(..)? propagate naturally inside a
handler.
impl From<Error> for ConnectError
Lets Response::try_with_header(..)? propagate naturally inside a
handler.
Source§impl IntoResponse for ConnectError
Available on crate feature axum only.
impl IntoResponse for ConnectError
axum only.Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl Freeze for ConnectError
impl RefUnwindSafe for ConnectError
impl Send for ConnectError
impl Sync for ConnectError
impl Unpin for ConnectError
impl UnsafeUnpin for ConnectError
impl UnwindSafe for ConnectError
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService and no state. Read more