Skip to content

Commit

Permalink
Simplified some code
Browse files Browse the repository at this point in the history
  • Loading branch information
LyonSyonII committed Nov 21, 2023
1 parent 5d63e71 commit c21c64a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ enum Error {
BodyNotCorrect,
}
impl Reject for Error {}
impl Error {
fn not_authorized() -> Rejection {
warp::reject::custom(Self::NotAuthorized)
}
fn body_not_correct() -> Rejection {
warp::reject::custom(Self::BodyNotCorrect)
}
}

/*
curl --request POST \
Expand Down Expand Up @@ -97,12 +105,12 @@ async fn main() -> Result<(), &'static str> {
.and_then(move |auth: String| async move {
(auth == authorization)
.then_some(())
.ok_or(warp::reject::custom(Error::NotAuthorized))
.ok_or(Error::not_authorized())
})
.untuple_one();
let process_input = warp::body::content_length_limit(512)
.and(warp::body::json())
.or_else(|_| async move { Err(warp::reject::custom(Error::BodyNotCorrect)) });
.or_else(|_| async move { Err(Error::body_not_correct()) });
let run_input = move |i: Input| run(i.code, semaphore, semaphore_wait, kill_timeout);

let filter = route
Expand Down

0 comments on commit c21c64a

Please sign in to comment.