Struct nickel::NickelError [] [src]

pub struct NickelError<'a, D: 'a = ()> {
    pub stream: Option<Response<'a, D, Streaming>>,
    pub message: Cow<'static, str>,
}

NickelError is the basic error type for HTTP errors as well as user defined errors. One can pattern match against the kind property to handle the different cases.

Fields

Methods

impl<'a, D> NickelError<'a, D>
[src]

Creates a new NickelError instance.

You should probably use Response#error in favor of this.

Examples


use nickel::{Request, Response, MiddlewareResult, NickelError};
use nickel::status::StatusCode;

fn handler<'a, D>(_: &mut Request<D>, res: Response<'a, D>) -> MiddlewareResult<'a, D> {
    Err(NickelError::new(res, "Error Parsing JSON", StatusCode::BadRequest))
}

Creates a new NickelError without a Response.

This should only be called in a state where the Response has failed in an unrecoverable state. If there is an available Response then it must be provided to new so that the underlying stream can be flushed, allowing future requests.

This is considered unsafe as deadlock can occur if the Response does not have the underlying stream flushed when processing is finished.

Trait Implementations

impl<'a, T, D> From<(Response<'a, D>, (StatusCode, T))> for NickelError<'a, D> where
    T: Into<Box<Error + 'static>>, 
[src]

Performs the conversion.

impl<'a, D> From<(Response<'a, D>, String)> for NickelError<'a, D>
[src]

Performs the conversion.

impl<'a, D> From<(Response<'a, D>, StatusCode)> for NickelError<'a, D>
[src]

Performs the conversion.