Struct nickel::NickelError

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

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

stream: Option<Response<'a, D, Streaming>>message: Cow<'static, str>

Implementations

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

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Get the TypeId of this object.