Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
fix: respond with 404 if project is not found
Browse files Browse the repository at this point in the history
Fixes #2427

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
  • Loading branch information
geigerzaehler committed Sep 29, 2021
1 parent 92ed914 commit 8f39aa9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions proxy/api/src/http/error.rs
Expand Up @@ -51,6 +51,16 @@ pub struct Response {
pub message: String,
}

impl Response {
pub fn internal_server_error(err: impl std::error::Error) -> Self {
Self {
status_code: StatusCode::INTERNAL_SERVER_ERROR,
variant: "INTERNAL_SERVER_ERROR",
message: err.to_string(),
}
}
}

impl warp::reject::Reject for Response {}

#[allow(clippy::unused_async)]
Expand Down Expand Up @@ -289,11 +299,20 @@ impl From<&error::Error> for Response {
variant: "FORBIDDEN",
message: err.to_string(),
},
_ => Self {
error::Error::ProjectNotFound => Self {
status_code: StatusCode::NOT_FOUND,
variant: "PROJECT_NOT_FOUND",
message: "Project not found".to_string(),
},
error::Error::MissingDefaultBranch => Self {
status_code: StatusCode::INTERNAL_SERVER_ERROR,
variant: "INTERNAL_SERVER_ERROR",
message: err.to_string(),
variant: "MISSING_DEFAULT_BRANCH",
message: "Default branch for project is missing".to_string(),
},
error::Error::Peer(_)
| error::Error::Io(_)
| error::Error::Store(_)
| error::Error::WaitingRoom(_) => Self::internal_server_error(err),
}
}
}

0 comments on commit 8f39aa9

Please sign in to comment.