logo
Expand description

Catcher tarit and it’s defalut implement CatcherImpl.

A web application can specify several different Catchers to handle errors.

They can be set via the with_catchers function of Server:

Example


struct Handle404;
impl Catcher for Handle404 {
    fn catch(&self, _req: &Request, _depot: &Depot, res: &mut Response) -> bool {
        if let Some(StatusCode::NOT_FOUND) = res.status_code() {
            res.render("Custom 404 Error Page");
            true
        } else {
            false
        }
    }
}

#[tokio::main]
async fn main() {
    let catchers: Vec<Box<dyn Catcher>> = vec![Box::new(Handle404)];
    Service::new(Router::new()).with_catchers(catchers);
}

When there is an error in the website request result, first try to set the error page through the Catcher set by the user. If the Catcher catches the error, it will return true.

If your custom catchers does not capture this error, then the system uses the default CatcherImpl to capture processing errors and send the default error page.

Structs

Default implementation of Catcher.

Traits

Catch http response error.

Functions

Create bytes from StatusError.