chore: send rest of the errors to the catchers

This commit is contained in:
Zomatree
2025-07-02 01:16:16 +01:00
parent cf4fe859bf
commit 46e127ccd2
8 changed files with 27 additions and 3 deletions

View File

@@ -636,6 +636,8 @@ impl<'r> FromRequest<'r> for EventHeader<'r> {
async fn from_request(request: &'r Request<'_>) -> rocket::request::Outcome<Self, Self::Error> {
let headers = request.headers();
let Some(event) = headers.get_one("X-GitHub-Event") else {
request.local_cache(|| Some(create_error!(InvalidOperation)));
return rocket::request::Outcome::Error((
Status::BadRequest,
create_error!(InvalidOperation),

View File

@@ -14,6 +14,22 @@ pub fn unprocessable_entity(req: &Request) -> Result<()> {
}
}
#[catch(401)]
pub fn unauthorized(req: &Request) -> Result<()> {
match req.local_cache(|| None::<Error>) {
Some(e) => Err(e.clone()),
None => Err(create_error!(NotAuthenticated))
}
}
#[catch(409)]
pub fn conflict(req: &Request) -> Result<()> {
match req.local_cache(|| None::<Error>) {
Some(e) => Err(e.clone()),
None => Err(create_error!(Conflict))
}
}
pub fn all_catchers() -> Vec<Catcher> {
catchers![not_found, unprocessable_entity]
catchers![not_found, unprocessable_entity, unauthorized, conflict]
}

View File

@@ -3,12 +3,12 @@ use std::hash::Hasher;
use std::ops::Add;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use crate::util::json::Json;
use authifier::models::Session;
use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::uri::Origin;
use rocket::http::{Method, Status};
use rocket::request::{FromRequest, Outcome};
use crate::util::json::Json;
use rocket::{Data, Request, Response};
use revolt_rocket_okapi::gen::OpenApiGenerator;