feat: better error handling

This commit is contained in:
Zomatree
2025-07-01 19:06:38 +01:00
parent ed22b3a5ce
commit 3d6f39a0eb
17 changed files with 336 additions and 55 deletions

View File

@@ -0,0 +1,19 @@
use rocket::{catch, Catcher, Request};
use revolt_result::{create_error, Error, Result};
#[catch(404)]
pub fn not_found() -> Result<()> {
Err(create_error!(NotFound))
}
#[catch(422)]
pub fn unprocessable_entity(req: &Request) -> Result<()> {
match req.local_cache(|| None::<Error>) {
Some(e) => Err(e.clone()),
None => Err(create_error!(UnprocessableEntity))
}
}
pub fn all_catchers() -> Vec<Catcher> {
catchers![not_found, unprocessable_entity]
}