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
sourceimpl<'a, D> NickelError<'a, D>
impl<'a, D> NickelError<'a, D>
sourcepub fn new<T>(
stream: Response<'a, D, Fresh>,
message: T,
status_code: StatusCode
) -> NickelError<'a, D>where
T: Into<Cow<'static, str>>,
pub fn new<T>(
stream: Response<'a, D, Fresh>,
message: T,
status_code: StatusCode
) -> NickelError<'a, D>where
T: Into<Cow<'static, str>>,
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))
}
sourcepub unsafe fn without_response<T>(message: T) -> NickelError<'a, D>where
T: Into<Cow<'static, str>>,
pub unsafe fn without_response<T>(message: T) -> NickelError<'a, D>where
T: Into<Cow<'static, str>>,
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.
pub fn end(self) -> Option<Result<()>>
Trait Implementations
sourceimpl<'a, T, D> From<(Response<'a, D, Fresh>, (StatusCode, T))> for NickelError<'a, D>where
T: Into<Box<dyn Error + 'static>>,
impl<'a, T, D> From<(Response<'a, D, Fresh>, (StatusCode, T))> for NickelError<'a, D>where
T: Into<Box<dyn Error + 'static>>,
sourcefn from(
(res, (errorcode, err)): (Response<'a, D>, (StatusCode, T))
) -> NickelError<'a, D>
fn from(
(res, (errorcode, err)): (Response<'a, D>, (StatusCode, T))
) -> NickelError<'a, D>
Converts to this type from the input type.
sourceimpl<'a, D> From<(Response<'a, D, Fresh>, StatusCode)> for NickelError<'a, D>
impl<'a, D> From<(Response<'a, D, Fresh>, StatusCode)> for NickelError<'a, D>
sourcefn from((res, code): (Response<'a, D>, StatusCode)) -> NickelError<'a, D>
fn from((res, code): (Response<'a, D>, StatusCode)) -> NickelError<'a, D>
Converts to this type from the input type.
Auto Trait Implementations
impl<'a, D = ()> !RefUnwindSafe for NickelError<'a, D>
impl<'a, D = ()> !Send for NickelError<'a, D>
impl<'a, D = ()> !Sync for NickelError<'a, D>
impl<'a, D> Unpin for NickelError<'a, D>
impl<'a, D = ()> !UnwindSafe for NickelError<'a, D>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more