#[non_exhaustive]pub enum Error {
BadRequest(String),
Unauthorized(String),
Forbidden(String),
NotFound(String),
Internal(String),
Validation(Vec<FieldError>),
Custom(u16, String),
}Expand description
Framework error type that maps to HTTP status codes
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
BadRequest(String)
400 Bad Request
401 Unauthorized
Forbidden(String)
403 Forbidden
NotFound(String)
404 Not Found
Internal(String)
500 Internal Server Error
Validation(Vec<FieldError>)
422 Unprocessable Content with one entry per invalid field, rendered as
{"error": "Validation failed", "status": 422, "fields": {"title": ["..."]}}.
See Validator.
Custom(u16, String)
Custom status code + message
Implementations§
Source§impl Error
impl Error
pub fn status_code(&self) -> u16
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
The status as an http::StatusCode (invalid custom codes become 500)
pub fn message(&self) -> &str
Source§impl Error
impl Error
pub fn bad_request(msg: impl Into<String>) -> Self
pub fn forbidden(msg: impl Into<String>) -> Self
pub fn not_found(msg: impl Into<String>) -> Self
pub fn internal(msg: impl Into<String>) -> Self
Sourcepub fn validation(fields: Vec<FieldError>) -> Self
pub fn validation(fields: Vec<FieldError>) -> Self
422 with the given invalid fields
Sourcepub fn fields(&self) -> &[FieldError]
pub fn fields(&self) -> &[FieldError]
The invalid fields of a Error::Validation, empty for other errors
pub fn custom(status: u16, msg: impl Into<String>) -> Self
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<ClientError> for Error
impl From<ClientError> for Error
Source§fn from(e: ClientError) -> Self
fn from(e: ClientError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
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
Mutably borrows from an owned value. Read more