mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-22 16:59:17 +02:00
Added error 501
This commit is contained in:
parent
3c1d88bd42
commit
5c7c572641
2 changed files with 9 additions and 3 deletions
|
@ -26,3 +26,7 @@ impl warp::reject::Reject for UnauthorizedError {}
|
|||
pub struct ForbiddenError;
|
||||
impl warp::reject::Reject for ForbiddenError {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NotImplementedError;
|
||||
impl warp::reject::Reject for NotImplementedError {}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use reqwest::StatusCode;
|
|||
use warp::Filter;
|
||||
use warp::reply::Reply;
|
||||
|
||||
use crate::error_responses::{ErrorMessage, InternalServerError, BadRequestError, NotFoundError};
|
||||
use crate::error_responses::{ErrorMessage, InternalServerError, BadRequestError, NotFoundError, NotImplementedError};
|
||||
use crate::v1::get_v1_routes;
|
||||
use crate::{Logger, parse_ip};
|
||||
|
||||
|
@ -24,7 +24,7 @@ pub async fn serve() {
|
|||
let routes = favicon.or(get_v1_routes())
|
||||
.recover(handle_rejection);
|
||||
|
||||
|
||||
|
||||
async fn handle_rejection(err: warp::Rejection) -> Result<impl Reply, Infallible> {
|
||||
let (code, message) = if err.find::<InternalServerError>().is_some() {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Internal Server Error")
|
||||
|
@ -32,6 +32,8 @@ pub async fn serve() {
|
|||
(StatusCode::BAD_REQUEST, "Bad Request")
|
||||
} else if err.is_not_found() || err.find::<NotFoundError>().is_some() {
|
||||
(StatusCode::NOT_FOUND, "Not Found")
|
||||
} else if err.find::<NotImplementedError>().is_some() {
|
||||
(StatusCode::NOT_IMPLEMENTED, "Not Implemented")
|
||||
} else {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Unhandled Rejection") // Default case
|
||||
};
|
||||
|
@ -40,7 +42,7 @@ pub async fn serve() {
|
|||
code: code.as_u16(),
|
||||
message: message.into(),
|
||||
});
|
||||
|
||||
|
||||
Ok(warp::reply::with_status(json, code))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue