dhttp/core/
errorhandler.rs

1use crate::reqres::{HttpRequest, HttpResponse, StatusCode};
2use crate::core::HttpError;
3
4/// Handler for possible service errors
5///
6/// Returned status code (`res.code`) is not used, it is overriden by original status code.
7/// This is made to avoid returning `200 Ok` errors
8///
9/// If you want to change the code, consider altering the [`HttpError`] implementation
10pub trait HttpErrorHandler: Send + Sync + 'static {
11    /// Constructs an [`HttpResponse`] from given [`HttpError`]
12    fn error(&self, req: &HttpRequest, error: &dyn HttpError) -> HttpResponse;
13
14    /// Shows a plain error code page for internal errors
15    fn plain_code(&self, code: StatusCode) -> HttpResponse;
16}