Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.

Commit c7a6f49

Browse files
committed
Update warp routes
- Update warp routes to have the path filter take precedence. - Update problem unpack function to unpack 405 after everything else and before 500.
1 parent d8000c9 commit c7a6f49

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/helpers/problem.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn pack(err: anyhow::Error) -> Problem {
1818
match err {
1919
auth::AuthError::InvalidCredentials => {
2020
return Problem::new("Invalid credentials.")
21-
.set_status(http::StatusCode::BAD_REQUEST)
21+
.set_status(http::StatusCode::UNAUTHORIZED)
2222
.set_detail("The passed credentials were invalid.")
2323
}
2424
auth::AuthError::ArgonError => (),
@@ -60,17 +60,17 @@ pub async fn unpack(rejection: Rejection) -> Result<impl Reply, Infallible> {
6060
let reply = if rejection.is_not_found() {
6161
let problem = Problem::with_title_and_type_from_status(http::StatusCode::NOT_FOUND);
6262
reply_from_problem(&problem)
63-
} else if let Some(_) = rejection.find::<warp::reject::MethodNotAllowed>() {
64-
let problem =
65-
Problem::with_title_and_type_from_status(http::StatusCode::METHOD_NOT_ALLOWED);
66-
reply_from_problem(&problem)
6763
} else if let Some(problem) = rejection.find::<Problem>() {
6864
reply_from_problem(problem)
6965
} else if let Some(e) = rejection.find::<warp::filters::body::BodyDeserializeError>() {
7066
let problem = Problem::new("Invalid Request Body.")
7167
.set_status(http::StatusCode::BAD_REQUEST)
7268
.set_detail(format!("Request body is invalid. {}", e));
7369
reply_from_problem(&problem)
70+
} else if let Some(_) = rejection.find::<warp::reject::MethodNotAllowed>() {
71+
let problem =
72+
Problem::with_title_and_type_from_status(http::StatusCode::METHOD_NOT_ALLOWED);
73+
reply_from_problem(&problem)
7474
} else {
7575
let problem =
7676
Problem::with_title_and_type_from_status(http::StatusCode::INTERNAL_SERVER_ERROR);

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ async fn main() -> anyhow::Result<()> {
6161
.allow_any_origin()
6262
.build();
6363
let log = warp::log("api::request");
64-
let status = warp::get()
65-
.and(warp::path("status"))
64+
let status = warp::path("status")
65+
.and(warp::get())
6666
.and(warp::path::end())
6767
.map(|| format!("OK"));
68-
let auth = warp::post()
69-
.and(warp::path("auth"))
68+
let auth = warp::path("auth")
69+
.and(warp::post())
7070
.and(warp::path::end())
7171
.and(env.clone())
7272
.and(warp::body::json())
@@ -120,8 +120,8 @@ async fn main() -> anyhow::Result<()> {
120120

121121
let coordinator = Arc::new(Coordinator::new(graphql::schema()));
122122

123-
let query = warp::post()
124-
.and(warp::path("query"))
123+
let query = warp::path("query")
124+
.and(warp::post())
125125
.and(warp::path::end())
126126
.and(make_graphql_filter(graphql::schema(), context.clone()));
127127

0 commit comments

Comments
 (0)