Struct pavex::blueprint::router::RegisteredFallback
source · pub struct RegisteredFallback<'a> { /* private fields */ }
Expand description
The type returned by Blueprint::fallback
.
It allows you to further configure the behaviour of the registered handler.
Implementations§
source§impl<'a> RegisteredFallback<'a>
impl<'a> RegisteredFallback<'a>
sourcepub fn error_handler(self, error_handler: RawIdentifiers) -> Self
pub fn error_handler(self, error_handler: RawIdentifiers) -> Self
Register an error handler.
Error handlers convert the error type returned by your request handler into an HTTP response.
Error handlers CANNOT consume the error type, they must take a reference to the
error as input.
Error handlers can have additional input parameters alongside the error, as long as there
are constructors registered for those parameter types.
use pavex::f;
use pavex::blueprint::Blueprint;
use pavex::response::Response;
fn fallback() -> Result<Response, RuntimeError> {
// [...]
}
fn error_to_response(error: &ConfigurationError, log_level: LogLevel) -> Response {
// [...]
}
let mut bp = Blueprint::new();
bp.fallback(f!(crate::fallback))
.error_handler(f!(crate::error_to_response));
If an error handler has already been registered for the same error type, it will be overwritten.
§Common Errors
Pavex will fail to generate the runtime code for your application if you register
an error handler for an infallible request handler (i.e. a request handler that doesn’t
return a Result
).