Enum pencil::http_errors::HTTPError [] [src]

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 pencil::{Request, PencilResult, PenHTTPError};
use 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 pencil::{Request, PencilResult};
use pencil::abort;


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

Variants

BadRequest
Unauthorized
Forbidden
NotFound
MethodNotAllowed
NotAcceptable
RequestTimeout
Conflict
Gone
LengthRequired
PreconditionFailed
RequestEntityTooLarge
RequestURITooLarge
UnsupportedMediaType
RequestedRangeNotSatisfiable
ExpectationFailed
ImATeapot
UnprocessableEntity
PreconditionRequired
TooManyRequests
RequestHeaderFieldsTooLarge
InternalServerError
NotImplemented
BadGateway
ServiceUnavailable

Methods

impl HTTPError

fn new(code: u16) -> HTTPError

Create a new HTTPError.

fn code(&self) -> u16

The status code.

fn name(&self) -> &str

The status name.

fn get_body(&self) -> String

Get the HTML body.

fn to_response(&self) -> Response

Get a response object.

Trait Implementations

impl Display for HTTPError

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

impl Error for HTTPError

fn description(&self) -> &str

fn cause(&self) -> Option<&Error>

Derived Implementations

impl Debug for HTTPError

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Clone for HTTPError

fn clone(&self) -> HTTPError

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