ConnectError

Struct ConnectError 

Source
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

Source

pub fn new<S: Into<String>>(code: Code, message: S) -> Self

Create a new error with a code and message.

Source

pub fn from_code(code: Code) -> Self

Create a new error with just a code.

Source

pub fn new_unimplemented() -> Self

Create an unimplemented error.

Source

pub fn new_invalid_argument<S: Into<String>>(message: S) -> Self

Create an invalid argument error.

Source

pub fn new_not_found<S: Into<String>>(message: S) -> Self

Create a not found error.

Source

pub fn new_permission_denied<S: Into<String>>(message: S) -> Self

Create a permission denied error.

Source

pub fn new_unauthenticated<S: Into<String>>(message: S) -> Self

Create an unauthenticated error.

Source

pub fn new_internal<S: Into<String>>(message: S) -> Self

Create an internal error.

Source

pub fn new_unavailable<S: Into<String>>(message: S) -> Self

Create an unavailable error.

Source

pub fn new_already_exists<S: Into<String>>(message: S) -> Self

Create an already exists error.

Source

pub fn new_resource_exhausted<S: Into<String>>(message: S) -> Self

Create a resource exhausted error.

Source

pub fn new_failed_precondition<S: Into<String>>(message: S) -> Self

Create a failed precondition error.

Source

pub fn new_aborted<S: Into<String>>(message: S) -> Self

Create an aborted error.

Source

pub fn code(&self) -> Code

Get the error code.

Source

pub fn message(&self) -> Option<&str>

Get the error message.

Source

pub fn details(&self) -> &[ErrorDetail]

Get the error details.

Source

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);
Source

pub fn add_error_detail(self, detail: ErrorDetail) -> Self

Add a pre-constructed ErrorDetail.

Source

pub fn meta(&self) -> Option<&HeaderMap>

Get the metadata headers, if any.

Source

pub fn meta_mut(&mut self) -> &mut HeaderMap

Get mutable access to metadata headers. Lazily initializes the HeaderMap if not present.

Source

pub fn with_meta<K, V>(self, key: K, value: V) -> Self
where K: AsRef<str>, V: AsRef<str>,

Add a metadata header.

Source

pub fn set_meta_from_headers(self, headers: &HeaderMap) -> Self

Set metadata from HeaderMap.

Source§

impl ConnectError

Source

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

Source§

fn clone(&self) -> ConnectError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConnectError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<(StatusCode, String)> for ConnectError

Source§

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

Source§

fn from(infallible: Infallible) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for ConnectError

Source§

fn into_response(self) -> Response

Create a response.
Source§

impl Serialize for ConnectError

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T, S> Handler<IntoResponseHandler, S> for T
where T: IntoResponse + Clone + Send + Sync + 'static,

Source§

type Future = Ready<Response<Body>>

The type of future calling this handler returns.
Source§

fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future

Call the handler with the given request.
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>>,

Apply a tower::Layer to the handler. Read more
Source§

fn with_state(self, state: S) -> HandlerService<Self, T, S>

Convert the handler into a Service by providing the state
Source§

impl<H, T> HandlerWithoutStateExt<T> for H
where H: Handler<T, ()>,

Source§

fn into_service(self) -> HandlerService<H, T, ()>

Convert the handler into a Service and no state.
Source§

fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>

Convert the handler into a MakeService and no state. Read more
Source§

fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>

Convert the handler into a MakeService which stores information about the incoming connection and has no state. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,