From f86e4308398c52622ccb2fbc3851745cba01ddb9 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Thu, 15 Apr 2021 13:10:18 +0300 Subject: Remove unused code --- src/error.rs | 38 -------------------------------------- src/lib.rs | 1 - 2 files changed, 39 deletions(-) delete mode 100644 src/error.rs diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index 7339a06..0000000 --- a/src/error.rs +++ /dev/null @@ -1,38 +0,0 @@ -use log::warn; -use serde::Serialize; -use std::convert::Infallible; -use warp::{http::StatusCode, Rejection, Reply}; - -#[derive(Serialize)] -struct ErrorResponse { - message: String, -} - -pub async fn handle_rejection(err: Rejection) -> std::result::Result { - let code; - let message; - - if err.is_not_found() { - code = StatusCode::NOT_FOUND; - message = "Requested resource is not found"; - } else if let Some(_) = err.find::() { - code = StatusCode::BAD_REQUEST; - message = "Error: JSON body is not formatted correctly, check your payload"; - } else if let Some(_) = err.find::() { - code = StatusCode::METHOD_NOT_ALLOWED; - message = "Error: Authorization header missing, cannot authorize"; - } else if let Some(_) = err.find::() { - code = StatusCode::METHOD_NOT_ALLOWED; - message = "Error: method not allowed on this endpoint"; - } else { - warn!("unhandled error: {:?}", err); - code = StatusCode::INTERNAL_SERVER_ERROR; - message = "Internal Server Error"; - } - - let json = warp::reply::json(&ErrorResponse { - message: message.to_owned(), - }); - - Ok(warp::reply::with_status(json, code)) -} diff --git a/src/lib.rs b/src/lib.rs index 7a24f9f..82fb51f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,6 @@ //! `Authorization`: The request header should have Bearer JWT.Token signed with Student Public Key pub mod custom_filters; -pub mod error; pub mod handlers; pub mod routes; pub mod schema; -- cgit v1.2.3-70-g09d2