pub struct ApiError {
pub kind: String,
pub code: u16,
pub message: String,
pub details: Option<Value>,
}
Expand description
Represents a structured error that can be easily serialized and sent as an HTTP response.
Fields§
§kind: String
A machine-readable error type or category.
code: u16
The HTTP status code associated with this error. This field is not serialized.
message: String
A human-readable message describing the error.
details: Option<Value>
Optional structured details about the error.
Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn new(
code: u16,
kind: &str,
message: String,
details: Option<Value>,
) -> Self
pub fn new( code: u16, kind: &str, message: String, details: Option<Value>, ) -> Self
Creates a new ApiError
.
§Arguments
code
- The HTTP status code for this error.kind
- A string slice representing the kind or category of the error.message
- AString
containing the descriptive message for the error.details
- Optionalserde_json::Value
for structured error details.
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()
Source§impl ResponseError for ApiError
impl ResponseError for ApiError
Source§fn status_code(&self) -> StatusCode
fn status_code(&self) -> StatusCode
Returns appropriate status code for error. Read more
Source§fn error_response(&self) -> HttpResponse
fn error_response(&self) -> HttpResponse
Creates full response for error. Read more
Auto Trait Implementations§
impl Freeze for ApiError
impl RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin 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