rocket_json::error

Struct Error

Source
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 str

Implementations§

Source§

impl Error

Source

pub const MultipleChoices: Error = _

Error with code 300 and reason Multiple Choices .

Source

pub const MovedPermanently: Error = _

Error with code 301 and reason Moved Permanently .

Source

pub const Found: Error = _

Error with code 302 and reason Found .

Source

pub const SeeOther: Error = _

Error with code 303 and reason See Other .

Source

pub const NotModified: Error = _

Error with code 304 and reason Not Modified .

Source

pub const UseProxy: Error = _

Error with code 305 and reason Use Proxy .

Source

pub const TemporaryRedirect: Error = _

Error with code 307 and reason Temporary Redirect .

Source

pub const PermanentRedirect: Error = _

Error with code 308 and reason Permanent Redirect .

Source

pub const BadRequest: Error = _

Error with code 400 and reason Bad Request .

Source

pub const Unauthorized: Error = _

Error with code 401 and reason Unauthorized .

Source

pub const PaymentRequired: Error = _

Error with code 402 and reason Payment Required .

Source

pub const Forbidden: Error = _

Error with code 403 and reason Forbidden .

Source

pub const NotFound: Error = _

Error with code 404 and reason Not Found .

Source

pub const MethodNotAllowed: Error = _

Error with code 405 and reason Method Not Allowed .

Source

pub const NotAcceptable: Error = _

Error with code 406 and reason Not Acceptable .

Source

pub const ProxyAuthenticationRequired: Error = _

Error with code 407 and reason Proxy Authentication Required .

Source

pub const RequestTimeout: Error = _

Error with code 408 and reason Request Timeout .

Source

pub const Conflict: Error = _

Error with code 409 and reason Conflict .

Source

pub const Gone: Error = _

Error with code 410 and reason Gone .

Source

pub const LengthRequired: Error = _

Error with code 411 and reason Length Required .

Source

pub const PreconditionFailed: Error = _

Error with code 412 and reason Precondition Failed .

Source

pub const PayloadTooLarge: Error = _

Error with code 413 and reason Payload Too Large .

Source

pub const UriTooLong: Error = _

Error with code 414 and reason URI Too Long .

Source

pub const UnsupportedMediaType: Error = _

Error with code 415 and reason Unsupported Media Type .

Source

pub const RangeNotSatisfiable: Error = _

Error with code 416 and reason Range Not Satisfiable .

Source

pub const ExpectationFailed: Error = _

Error with code 417 and reason Expectation Failed .

Source

pub const ImATeapot: Error = _

Error with code 418 and reason I’m a teapot .

Source

pub const MisdirectedRequest: Error = _

Error with code 421 and reason Misdirected Request .

Source

pub const UnprocessableEntity: Error = _

Error with code 422 and reason Unprocessable Entity .

Source

pub const Locked: Error = _

Error with code 423 and reason Locked .

Source

pub const FailedDependency: Error = _

Error with code 424 and reason Failed Dependency .

Source

pub const UpgradeRequired: Error = _

Error with code 426 and reason Upgrade Required .

Source

pub const PreconditionRequired: Error = _

Error with code 428 and reason Precondition Required .

Source

pub const TooManyRequests: Error = _

Error with code 429 and reason Too Many Requests .

Source

pub const RequestHeaderFieldsTooLarge: Error = _

Error with code 431 and reason Request Header Fields Too Large .

Source

pub const UnavailableForLegalReasons: Error = _

Error with code 451 and reason Unavailable For Legal Reasons .

Source

pub const InternalServerError: Error = _

Error with code 500 and reason Internal Server Error .

Source

pub const NotImplemented: Error = _

Error with code 501 and reason Not Implemented .

Source

pub const BadGateway: Error = _

Error with code 502 and reason Bad Gateway .

Source

pub const ServiceUnavailable: Error = _

Error with code 503 and reason Service Unavailable .

Source

pub const GatewayTimeout: Error = _

Error with code 504 and reason Gateway Timeout .

Source

pub const HttpVersionNotSupported: Error = _

Error with code 505 and reason HTTP Version Not Supported .

Source

pub const VariantAlsoNegotiates: Error = _

Error with code 506 and reason Variant Also Negotiates .

Source

pub const InsufficientStorage: Error = _

Error with code 507 and reason Insufficient Storage .

Source

pub const LoopDetected: Error = _

Error with code 508 and reason Loop Detected .

Source

pub const NotExtended: Error = _

Error with code 510 and reason Not Extended .

Source

pub const NetworkAuthenticationRequired: Error = _

Error with code 511 and reason Network Authentication Required .

Source

pub fn new(code: u16, reason: &'static str) -> Self

Source

pub fn extend(self, data: JsonValue) -> Self

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Status> for Error

Source§

fn from(status: Status) -> Self

Converts to this type from the input type.
Source§

impl Into<Status> for Error

Source§

fn into(self) -> Status

Converts this type into the (usually inferred) input type.
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Error) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'r> Responder<'r> for Error

Source§

fn respond_to(self, req: &Request<'_>) -> Result<Response<'r>, Status>

Returns Ok if a Response could be generated successfully. Otherwise, returns an Err with a failing Status. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, I> AsResult<T, I> for T
where I: Input,

Source§

fn as_result(self) -> Result<T, ParseErr<I>>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoCollection<T> for T

Source§

fn into_collection<A>(self) -> SmallVec<A>
where A: Array<Item = T>,

Converts self into a collection.
Source§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>
where F: FnMut(T) -> U, A: Array<Item = U>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V