Struct ErrorRouter

Source
pub struct ErrorRouter { /* private fields */ }

Implementations§

Source§

impl ErrorRouter

Source

pub fn new() -> Self

Examples found in repository?
examples/basic.rs (line 14)
7fn main() {
8    let handler = |_: &mut Request| {
9        Ok(Response::with((status::NotFound)))
10    };
11
12    let mut chain = Chain::new(handler);
13    chain.link_after({
14        let mut error_router = iron_error_router::ErrorRouter::new();
15
16        // In case the response is a 404, replace the response with your own.
17
18        error_router.handle_status(status::NotFound, |_: &mut Request| {
19            Ok(Response::with((
20                status::NotFound,
21                "Content not found."
22            )))
23        });
24
25        // Instead of writing a handler, you can just use a modifier:
26
27        error_router.modifier_for_status(
28            status::NotFound,
29            (status::NotFound, "Content not found.")
30        );
31
32        // Or an AfterMiddleware:
33
34        error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35            Ok(Response::with((status::NotFound, "Content not found.")))
36        });
37
38        error_router
39    });
40
41    Iron::new(chain).http("localhost:3000").unwrap();
42}
Source

pub fn handle_status<T: Handler>(&mut self, status: Status, handler: T)

Examples found in repository?
examples/basic.rs (lines 18-23)
7fn main() {
8    let handler = |_: &mut Request| {
9        Ok(Response::with((status::NotFound)))
10    };
11
12    let mut chain = Chain::new(handler);
13    chain.link_after({
14        let mut error_router = iron_error_router::ErrorRouter::new();
15
16        // In case the response is a 404, replace the response with your own.
17
18        error_router.handle_status(status::NotFound, |_: &mut Request| {
19            Ok(Response::with((
20                status::NotFound,
21                "Content not found."
22            )))
23        });
24
25        // Instead of writing a handler, you can just use a modifier:
26
27        error_router.modifier_for_status(
28            status::NotFound,
29            (status::NotFound, "Content not found.")
30        );
31
32        // Or an AfterMiddleware:
33
34        error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35            Ok(Response::with((status::NotFound, "Content not found.")))
36        });
37
38        error_router
39    });
40
41    Iron::new(chain).http("localhost:3000").unwrap();
42}
Source

pub fn after_status<T: AfterMiddleware>( &mut self, status: Status, middleware: T, )

Examples found in repository?
examples/basic.rs (lines 34-36)
7fn main() {
8    let handler = |_: &mut Request| {
9        Ok(Response::with((status::NotFound)))
10    };
11
12    let mut chain = Chain::new(handler);
13    chain.link_after({
14        let mut error_router = iron_error_router::ErrorRouter::new();
15
16        // In case the response is a 404, replace the response with your own.
17
18        error_router.handle_status(status::NotFound, |_: &mut Request| {
19            Ok(Response::with((
20                status::NotFound,
21                "Content not found."
22            )))
23        });
24
25        // Instead of writing a handler, you can just use a modifier:
26
27        error_router.modifier_for_status(
28            status::NotFound,
29            (status::NotFound, "Content not found.")
30        );
31
32        // Or an AfterMiddleware:
33
34        error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35            Ok(Response::with((status::NotFound, "Content not found.")))
36        });
37
38        error_router
39    });
40
41    Iron::new(chain).http("localhost:3000").unwrap();
42}
Source

pub fn modifier_for_status<T: Modifier<Response> + Send + Sync + Clone + 'static>( &mut self, status: Status, modifier: T, )

Examples found in repository?
examples/basic.rs (lines 27-30)
7fn main() {
8    let handler = |_: &mut Request| {
9        Ok(Response::with((status::NotFound)))
10    };
11
12    let mut chain = Chain::new(handler);
13    chain.link_after({
14        let mut error_router = iron_error_router::ErrorRouter::new();
15
16        // In case the response is a 404, replace the response with your own.
17
18        error_router.handle_status(status::NotFound, |_: &mut Request| {
19            Ok(Response::with((
20                status::NotFound,
21                "Content not found."
22            )))
23        });
24
25        // Instead of writing a handler, you can just use a modifier:
26
27        error_router.modifier_for_status(
28            status::NotFound,
29            (status::NotFound, "Content not found.")
30        );
31
32        // Or an AfterMiddleware:
33
34        error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35            Ok(Response::with((status::NotFound, "Content not found.")))
36        });
37
38        error_router
39    });
40
41    Iron::new(chain).http("localhost:3000").unwrap();
42}

Trait Implementations§

Source§

impl AfterMiddleware for ErrorRouter

Source§

fn after( &self, req: &mut Request<'_, '_>, res: Response, ) -> IronResult<Response>

Do whatever post-processing this middleware should do.
Source§

fn catch( &self, req: &mut Request<'_, '_>, err: IronError, ) -> IronResult<Response>

Respond to an error thrown by previous AfterMiddleware, the Handler, or a BeforeMiddleware. Read more
Source§

impl Default for ErrorRouter

Source§

fn default() -> ErrorRouter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<T> UnsafeAny for T
where T: Any,