feat: better error handling
This commit is contained in:
19
crates/delta/src/util/catchers.rs
Normal file
19
crates/delta/src/util/catchers.rs
Normal 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]
|
||||
}
|
||||
Reference in New Issue
Block a user