diff options
author | Yigit Sever | 2021-04-15 13:10:18 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-15 13:10:18 +0300 |
commit | 57d833094c4e5f54d2a8ad8816595eea7ddc21de (patch) | |
tree | ab8b15cfc199b406499239256b78fb0861322a24 /src | |
parent | 82f8e6877a57316860a9468f523decaae9f7529b (diff) | |
download | gradecoin-57d833094c4e5f54d2a8ad8816595eea7ddc21de.tar.gz gradecoin-57d833094c4e5f54d2a8ad8816595eea7ddc21de.tar.bz2 gradecoin-57d833094c4e5f54d2a8ad8816595eea7ddc21de.zip |
Remove unused code
Diffstat (limited to 'src')
-rw-r--r-- | src/error.rs | 38 | ||||
-rw-r--r-- | src/lib.rs | 1 |
2 files changed, 0 insertions, 39 deletions
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 @@ | |||
1 | use log::warn; | ||
2 | use serde::Serialize; | ||
3 | use std::convert::Infallible; | ||
4 | use warp::{http::StatusCode, Rejection, Reply}; | ||
5 | |||
6 | #[derive(Serialize)] | ||
7 | struct ErrorResponse { | ||
8 | message: String, | ||
9 | } | ||
10 | |||
11 | pub async fn handle_rejection(err: Rejection) -> std::result::Result<impl Reply, Infallible> { | ||
12 | let code; | ||
13 | let message; | ||
14 | |||
15 | if err.is_not_found() { | ||
16 | code = StatusCode::NOT_FOUND; | ||
17 | message = "Requested resource is not found"; | ||
18 | } else if let Some(_) = err.find::<warp::filters::body::BodyDeserializeError>() { | ||
19 | code = StatusCode::BAD_REQUEST; | ||
20 | message = "Error: JSON body is not formatted correctly, check your payload"; | ||
21 | } else if let Some(_) = err.find::<warp::reject::MissingHeader>() { | ||
22 | code = StatusCode::METHOD_NOT_ALLOWED; | ||
23 | message = "Error: Authorization header missing, cannot authorize"; | ||
24 | } else if let Some(_) = err.find::<warp::reject::MethodNotAllowed>() { | ||
25 | code = StatusCode::METHOD_NOT_ALLOWED; | ||
26 | message = "Error: method not allowed on this endpoint"; | ||
27 | } else { | ||
28 | warn!("unhandled error: {:?}", err); | ||
29 | code = StatusCode::INTERNAL_SERVER_ERROR; | ||
30 | message = "Internal Server Error"; | ||
31 | } | ||
32 | |||
33 | let json = warp::reply::json(&ErrorResponse { | ||
34 | message: message.to_owned(), | ||
35 | }); | ||
36 | |||
37 | Ok(warp::reply::with_status(json, code)) | ||
38 | } | ||
@@ -22,7 +22,6 @@ | |||
22 | //! `Authorization`: The request header should have Bearer JWT.Token signed with Student Public Key | 22 | //! `Authorization`: The request header should have Bearer JWT.Token signed with Student Public Key |
23 | 23 | ||
24 | pub mod custom_filters; | 24 | pub mod custom_filters; |
25 | pub mod error; | ||
26 | pub mod handlers; | 25 | pub mod handlers; |
27 | pub mod routes; | 26 | pub mod routes; |
28 | pub mod schema; | 27 | pub mod schema; |