Trait surf_disco::error::Error
pub trait Error: Error + Serialize + DeserializeOwned + Send + Sync + 'static {
// Required methods
fn catch_all(status: StatusCode, msg: String) -> Self;
fn status(&self) -> StatusCode;
// Provided methods
fn from_io_error(source: Error) -> Self { ... }
fn from_config_error(source: ConfigError) -> Self { ... }
fn from_route_error<E>(source: RouteError<E>) -> Self
where E: Display { ... }
fn from_request_error(source: RequestError) -> Self { ... }
fn from_socket_error<E>(source: SocketError<E>) -> Self
where E: Display { ... }
fn into_tide_error(self) -> Error { ... }
fn from_server_error(source: Error) -> Self { ... }
}
Expand description
Errors which can be serialized in a response body.
This trait can be used to define a standard error type returned by all API endpoints. When a request fails for any reason, the body of the response will contain a serialization of the error that caused the failure, upcasted into an anyhow::Error. If the error is an instance of the standard error type for that particular API, it can be deserialized and downcasted to this type on the client.
Other errors (those which don’t downcast to the API’s error type, such as errors generated from the [tide] framework) will be serialized as strings using their Display instance and encoded as an API error using the catch_all function.
Required Methods§
fn catch_all(status: StatusCode, msg: String) -> Self
fn status(&self) -> StatusCode
Provided Methods§
fn from_io_error(source: Error) -> Self
fn from_config_error(source: ConfigError) -> Self
fn from_route_error<E>(source: RouteError<E>) -> Selfwhere
E: Display,
fn from_request_error(source: RequestError) -> Self
fn from_socket_error<E>(source: SocketError<E>) -> Selfwhere
E: Display,
fn into_tide_error(self) -> Error
fn from_server_error(source: Error) -> Self
Object Safety§
This trait is not object safe.