[][src]Enum sharp_pencil::http_errors::HTTPError

pub enum HTTPError {
    BadRequest,
    Unauthorized,
    Forbidden,
    NotFound,
    MethodNotAllowed(Option<Vec<Method>>),
    NotAcceptable,
    RequestTimeout,
    Conflict,
    Gone,
    LengthRequired,
    PreconditionFailed,
    RequestEntityTooLarge,
    RequestURITooLarge,
    UnsupportedMediaType,
    RequestedRangeNotSatisfiable,
    ExpectationFailed,
    ImATeapot,
    UnprocessableEntity,
    PreconditionRequired,
    TooManyRequests,
    RequestHeaderFieldsTooLarge,
    InternalServerError,
    NotImplemented,
    BadGateway,
    ServiceUnavailable,
}

The HTTP Error type you can return from within your views to trigger a non-200 response. Here is one usage example:

use sharp_pencil::{Request, PencilResult, PenHTTPError};
use sharp_pencil::http_errors::NotFound;


fn view(_: &mut Request) -> PencilResult {
    return Err(PenHTTPError(NotFound))
}

Pencil comes with a shortcut that can be used to return non-200 HTTP error easily:

use sharp_pencil::{Request, PencilResult};
use sharp_pencil::abort;


fn view(_: &mut Request) -> PencilResult {
    return abort(404)
}

Variants

BadRequest
Unauthorized
Forbidden
NotFound
MethodNotAllowed(Option<Vec<Method>>)
NotAcceptable
RequestTimeout
Conflict
Gone
LengthRequired
PreconditionFailed
RequestEntityTooLarge
RequestURITooLarge
UnsupportedMediaType
RequestedRangeNotSatisfiable
ExpectationFailed
ImATeapot
UnprocessableEntity
PreconditionRequired
TooManyRequests
RequestHeaderFieldsTooLarge
InternalServerError
NotImplemented
BadGateway
ServiceUnavailable

Implementations

impl HTTPError[src]

pub fn new(code: u16) -> HTTPError[src]

Create a new HTTPError.

pub fn code(&self) -> u16[src]

The status code.

pub fn name(&self) -> &str[src]

The status name.

pub fn get_body(&self) -> String[src]

Get the HTML body.

pub fn to_response(&self) -> Response[src]

Get a response object.

Trait Implementations

impl Clone for HTTPError[src]

impl Debug for HTTPError[src]

impl Display for HTTPError[src]

impl Error for HTTPError[src]

impl From<HTTPError> for PencilError[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<T> UnsafeAny for T where
    T: Any