pub struct Error {
pub code: u16,
pub reason: &'static str,
/* private fields */
}Expand description
A specialized Status struct that responds json errors.
This struct implements a Responder that will return json.
§Examples
use rocket_contrib::json::JsonValue;
use rocket_json::{Error, Result};
fn example(error: bool) -> Result<JsonValue> {
if error {
// Rocket will return status code 503:
// { "reason": "Service Unavailable", "status": 503 }
return Err(Error::ServiceUnavailable);
}
// Rocket will return status code 200:
// { "example": 42 }
Ok(json!({ "example": 42 }))
}Fields§
§code: u16§reason: &'static strImplementations§
Source§impl Error
impl Error
Sourcepub const MultipleChoices: Error = _
pub const MultipleChoices: Error = _
Error with code
300
and reason
Multiple Choices
.
Sourcepub const MovedPermanently: Error = _
pub const MovedPermanently: Error = _
Error with code
301
and reason
Moved Permanently
.
Sourcepub const NotModified: Error = _
pub const NotModified: Error = _
Error with code
304
and reason
Not Modified
.
Sourcepub const TemporaryRedirect: Error = _
pub const TemporaryRedirect: Error = _
Error with code
307
and reason
Temporary Redirect
.
Sourcepub const PermanentRedirect: Error = _
pub const PermanentRedirect: Error = _
Error with code
308
and reason
Permanent Redirect
.
Sourcepub const BadRequest: Error = _
pub const BadRequest: Error = _
Error with code
400
and reason
Bad Request
.
Error with code
401
and reason
Unauthorized
.
Sourcepub const PaymentRequired: Error = _
pub const PaymentRequired: Error = _
Error with code
402
and reason
Payment Required
.
Sourcepub const MethodNotAllowed: Error = _
pub const MethodNotAllowed: Error = _
Error with code
405
and reason
Method Not Allowed
.
Sourcepub const NotAcceptable: Error = _
pub const NotAcceptable: Error = _
Error with code
406
and reason
Not Acceptable
.
Sourcepub const ProxyAuthenticationRequired: Error = _
pub const ProxyAuthenticationRequired: Error = _
Error with code
407
and reason
Proxy Authentication Required
.
Sourcepub const RequestTimeout: Error = _
pub const RequestTimeout: Error = _
Error with code
408
and reason
Request Timeout
.
Sourcepub const LengthRequired: Error = _
pub const LengthRequired: Error = _
Error with code
411
and reason
Length Required
.
Sourcepub const PreconditionFailed: Error = _
pub const PreconditionFailed: Error = _
Error with code
412
and reason
Precondition Failed
.
Sourcepub const PayloadTooLarge: Error = _
pub const PayloadTooLarge: Error = _
Error with code
413
and reason
Payload Too Large
.
Sourcepub const UriTooLong: Error = _
pub const UriTooLong: Error = _
Error with code
414
and reason
URI Too Long
.
Sourcepub const UnsupportedMediaType: Error = _
pub const UnsupportedMediaType: Error = _
Error with code
415
and reason
Unsupported Media Type
.
Sourcepub const RangeNotSatisfiable: Error = _
pub const RangeNotSatisfiable: Error = _
Error with code
416
and reason
Range Not Satisfiable
.
Sourcepub const ExpectationFailed: Error = _
pub const ExpectationFailed: Error = _
Error with code
417
and reason
Expectation Failed
.
Sourcepub const MisdirectedRequest: Error = _
pub const MisdirectedRequest: Error = _
Error with code
421
and reason
Misdirected Request
.
Sourcepub const UnprocessableEntity: Error = _
pub const UnprocessableEntity: Error = _
Error with code
422
and reason
Unprocessable Entity
.
Sourcepub const FailedDependency: Error = _
pub const FailedDependency: Error = _
Error with code
424
and reason
Failed Dependency
.
Sourcepub const UpgradeRequired: Error = _
pub const UpgradeRequired: Error = _
Error with code
426
and reason
Upgrade Required
.
Sourcepub const PreconditionRequired: Error = _
pub const PreconditionRequired: Error = _
Error with code
428
and reason
Precondition Required
.
Sourcepub const TooManyRequests: Error = _
pub const TooManyRequests: Error = _
Error with code
429
and reason
Too Many Requests
.
Sourcepub const RequestHeaderFieldsTooLarge: Error = _
pub const RequestHeaderFieldsTooLarge: Error = _
Error with code
431
and reason
Request Header Fields Too Large
.
Error with code
451
and reason
Unavailable For Legal Reasons
.
Sourcepub const InternalServerError: Error = _
pub const InternalServerError: Error = _
Error with code
500
and reason
Internal Server Error
.
Sourcepub const NotImplemented: Error = _
pub const NotImplemented: Error = _
Error with code
501
and reason
Not Implemented
.
Sourcepub const BadGateway: Error = _
pub const BadGateway: Error = _
Error with code
502
and reason
Bad Gateway
.
Error with code
503
and reason
Service Unavailable
.
Sourcepub const GatewayTimeout: Error = _
pub const GatewayTimeout: Error = _
Error with code
504
and reason
Gateway Timeout
.
Sourcepub const HttpVersionNotSupported: Error = _
pub const HttpVersionNotSupported: Error = _
Error with code
505
and reason
HTTP Version Not Supported
.
Sourcepub const VariantAlsoNegotiates: Error = _
pub const VariantAlsoNegotiates: Error = _
Error with code
506
and reason
Variant Also Negotiates
.
Sourcepub const InsufficientStorage: Error = _
pub const InsufficientStorage: Error = _
Error with code
507
and reason
Insufficient Storage
.
Sourcepub const LoopDetected: Error = _
pub const LoopDetected: Error = _
Error with code
508
and reason
Loop Detected
.
Sourcepub const NotExtended: Error = _
pub const NotExtended: Error = _
Error with code
510
and reason
Not Extended
.
Sourcepub const NetworkAuthenticationRequired: Error = _
pub const NetworkAuthenticationRequired: Error = _
Error with code
511
and reason
Network Authentication Required
.
pub fn new(code: u16, reason: &'static str) -> Self
pub fn extend(self, data: JsonValue) -> Self
Trait Implementations§
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)