From 57d833094c4e5f54d2a8ad8816595eea7ddc21de 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 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/error.rs (limited to '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)) -} -- cgit v1.2.3-70-g09d2