pub struct ConnectError { /* private fields */ }Expand description
An error that captures the key pieces of information for Connect RPC: a code, an optional message, metadata (HTTP headers), and optional error details.
Implementations§
Source§impl ConnectError
impl ConnectError
Sourcepub fn new<S: Into<String>>(code: Code, message: S) -> Self
pub fn new<S: Into<String>>(code: Code, message: S) -> Self
Create a new error with a code and message.
Sourcepub fn new_unimplemented() -> Self
pub fn new_unimplemented() -> Self
Create an unimplemented error.
Sourcepub fn new_invalid_argument<S: Into<String>>(message: S) -> Self
pub fn new_invalid_argument<S: Into<String>>(message: S) -> Self
Create an invalid argument error.
Sourcepub fn new_not_found<S: Into<String>>(message: S) -> Self
pub fn new_not_found<S: Into<String>>(message: S) -> Self
Create a not found error.
Sourcepub fn new_permission_denied<S: Into<String>>(message: S) -> Self
pub fn new_permission_denied<S: Into<String>>(message: S) -> Self
Create a permission denied error.
Sourcepub fn new_unauthenticated<S: Into<String>>(message: S) -> Self
pub fn new_unauthenticated<S: Into<String>>(message: S) -> Self
Create an unauthenticated error.
Sourcepub fn new_internal<S: Into<String>>(message: S) -> Self
pub fn new_internal<S: Into<String>>(message: S) -> Self
Create an internal error.
Create an unavailable error.
Sourcepub fn new_already_exists<S: Into<String>>(message: S) -> Self
pub fn new_already_exists<S: Into<String>>(message: S) -> Self
Create an already exists error.
Sourcepub fn new_resource_exhausted<S: Into<String>>(message: S) -> Self
pub fn new_resource_exhausted<S: Into<String>>(message: S) -> Self
Create a resource exhausted error.
Sourcepub fn new_failed_precondition<S: Into<String>>(message: S) -> Self
pub fn new_failed_precondition<S: Into<String>>(message: S) -> Self
Create a failed precondition error.
Sourcepub fn new_aborted<S: Into<String>>(message: S) -> Self
pub fn new_aborted<S: Into<String>>(message: S) -> Self
Create an aborted error.
Sourcepub fn details(&self) -> &[ErrorDetail]
pub fn details(&self) -> &[ErrorDetail]
Get the error details.
Sourcepub fn add_detail<S: Into<String>>(self, type_url: S, value: Vec<u8>) -> Self
pub fn add_detail<S: Into<String>>(self, type_url: S, value: Vec<u8>) -> Self
Add an error detail with type URL and protobuf-encoded bytes.
§Example
use prost::Message;
let duration = prost_types::Duration { seconds: 5, nanos: 0 };
let mut bytes = Vec::new();
duration.encode(&mut bytes).unwrap();
// Wrap in RetryInfo (field 1)
let mut retry_info_bytes = vec![0x0a, bytes.len() as u8];
retry_info_bytes.extend(bytes);
let err = ConnectError::new(Code::ResourceExhausted, "rate limited")
.add_detail("google.rpc.RetryInfo", retry_info_bytes);Sourcepub fn add_error_detail(self, detail: ErrorDetail) -> Self
pub fn add_error_detail(self, detail: ErrorDetail) -> Self
Add a pre-constructed ErrorDetail.
Sourcepub fn meta_mut(&mut self) -> &mut HeaderMap
pub fn meta_mut(&mut self) -> &mut HeaderMap
Get mutable access to metadata headers. Lazily initializes the HeaderMap if not present.
Sourcepub fn set_meta_from_headers(self, headers: &HeaderMap) -> Self
pub fn set_meta_from_headers(self, headers: &HeaderMap) -> Self
Set metadata from HeaderMap.
Source§impl ConnectError
impl ConnectError
Sourcepub fn into_streaming_response(self, use_proto: bool) -> Response
pub fn into_streaming_response(self, use_proto: bool) -> Response
Create a streaming error response with proper EndStream framing.
Per the Connect protocol, streaming responses must:
- Always return HTTP 200
- Use application/connect+json or application/connect+proto content-type
- Deliver errors in an EndStream frame (flags = 0x02)
This method should be used by streaming handlers when returning errors
before the stream has started. The use_proto flag determines the
response encoding (protobuf vs JSON).
Trait Implementations§
Source§impl Clone for ConnectError
impl Clone for ConnectError
Source§fn clone(&self) -> ConnectError
fn clone(&self) -> ConnectError
1.0.0 · 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 From<(StatusCode, String)> for ConnectError
impl From<(StatusCode, String)> for ConnectError
Source§fn from(value: (StatusCode, String)) -> Self
fn from(value: (StatusCode, String)) -> Self
Convert an HTTP status code and message into a ConnectError.
This provides a simple DX helper to lift common HTTP errors into Connect’s error space.
Source§impl From<Infallible> for ConnectError
impl From<Infallible> for ConnectError
Source§fn from(infallible: Infallible) -> Self
fn from(infallible: Infallible) -> Self
Source§impl IntoResponse for ConnectError
impl IntoResponse for ConnectError
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 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 moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
MakeService which stores information
about the incoming connection and has no state. Read more