pub struct ApiError { /* private fields */ }Expand description
An error with a Fusion Stack error code, rendered as one JSON:API error object. Return it from
a handler or middleware with ? or Err(..)?; it converts into laravel::Error.
use fusion_stack::errors::{ApiError, ApiErrorCode};
let error = ApiError::new(ApiErrorCode::InvalidFilter, "Unknown filter [colour].")
.parameter("filter[colour]");Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn new(code: impl ErrorCode, detail: impl Into<String>) -> Self
pub fn new(code: impl ErrorCode, detail: impl Into<String>) -> Self
An error with the code’s status and title.
Sourcepub fn not_found() -> Self
pub fn not_found() -> Self
A not_found error for a record that does not exist, worded without naming the model.
Sourcepub fn pointer(self, pointer: impl Into<String>) -> Self
pub fn pointer(self, pointer: impl Into<String>) -> Self
Points at the request document member at fault, as a JSON pointer such as /data/attributes/email.
Sourcepub fn parameter(self, parameter: impl Into<String>) -> Self
pub fn parameter(self, parameter: impl Into<String>) -> Self
Names the query parameter at fault, such as include.
Sourcepub fn header_source(self, header: impl Into<String>) -> Self
pub fn header_source(self, header: impl Into<String>) -> Self
Names the request header at fault, such as Api-Version.
Sourcepub fn link(self, name: impl Into<String>, url: impl Into<String>) -> Self
pub fn link(self, name: impl Into<String>, url: impl Into<String>) -> Self
Adds a link, such as about to an upgrade guide.
Sourcepub fn meta(self, key: impl Into<String>, value: impl Serialize) -> Self
pub fn meta(self, key: impl Into<String>, value: impl Serialize) -> Self
Adds a meta member, such as latest_version.
Trait Implementations§
Source§impl Error for ApiError
impl Error for ApiError
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()
Auto Trait Implementations§
impl Forget for ApiError
impl Freeze for ApiErrorwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<usize>: Freeze,
PhantomData<Bucket<String, Value>>: Freeze,
PhantomData<(String, String)>: Freeze,
impl Move for ApiError
impl RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl UnsafeUnpin for ApiErrorwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
PhantomData<Bucket<String, Value>>: UnsafeUnpin,
PhantomData<(String, String)>: UnsafeUnpin,
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