pub trait HttpError: Debug {
// Required methods
fn status_code(&self) -> u16;
fn error_code(&self) -> ErrorCode;
fn detail(&self) -> String;
}Expand description
Implement this trait on domain error types to get a blanket
From implementation into ApiError for free.
§Examples
use api_bones::error::{ApiError, ErrorCode, HttpError};
#[derive(Debug)]
struct BookingNotFound(u64);
impl HttpError for BookingNotFound {
fn status_code(&self) -> u16 { 404 }
fn error_code(&self) -> ErrorCode { ErrorCode::ResourceNotFound }
fn detail(&self) -> String { format!("Booking {} not found", self.0) }
}
let err: ApiError = BookingNotFound(42).into();
assert_eq!(err.status, 404);
assert_eq!(err.detail, "Booking 42 not found");Required Methods§
Sourcefn status_code(&self) -> u16
fn status_code(&self) -> u16
HTTP status code (e.g. 404).
Sourcefn error_code(&self) -> ErrorCode
fn error_code(&self) -> ErrorCode
Machine-readable ErrorCode for this error.