pub struct ApiError(pub Error);Expand description
Handler error for JSON endpoints: an Error rendered as a JSON body.
The body is {"error": {"status": 404, "message": "Not found"}}; a 422
adds "fields": {"title": ["can't be blank"]} (the shape Rails APIs use),
and a 401 adds the WWW-Authenticate: Bearer header. Internal messages are
logged and answered as Internal server error. Converts from Error
and [worker::Error], so ? works on everything Ocre returns. It is also
the rejection of Json and Page, and of Session
in API-only apps (without the html feature).
§Examples
use axum::{http::StatusCode, response::IntoResponse};
use ocre::{ApiError, Error};
let response = ApiError(Error::NotFound).into_response();
assert_eq!(response.status(), StatusCode::NOT_FOUND);
let response = ApiError::from(Error::Unauthorized).into_response();
assert_eq!(response.headers()["www-authenticate"], "Bearer");Tuple Fields§
§0: ErrorTrait Implementations§
Auto Trait Implementations§
impl Freeze for ApiError
impl RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl UnsafeUnpin for ApiError
impl UnwindSafe for ApiError
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