From 5654f08841828e3b724032d57d3a09703f0463ef Mon Sep 17 00:00:00 2001 From: cloudhead Date: Wed, 9 Aug 2023 12:01:14 +0200 Subject: [PATCH] httpd: Fix error status code on project not found It was 500, should be 404. --- radicle-httpd/src/api/error.rs | 1 + radicle-httpd/src/api/v1/projects.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index 6ecfacaf..d956090d 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -97,6 +97,7 @@ impl IntoResponse for Error { StatusCode::INTERNAL_SERVER_ERROR, Some(e.message().to_owned()), ), + Error::Storage(err) if err.is_not_found() => (StatusCode::NOT_FOUND, None), Error::BadRequest(msg) => (StatusCode::BAD_REQUEST, Some(msg)), other => { tracing::error!("Error: {message}"); diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index e2212ccd..f317a8af 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -836,6 +836,15 @@ mod routes { ); } + #[tokio::test] + async fn test_projects_not_found() { + let tmp = tempfile::tempdir().unwrap(); + let app = super::router(seed(tmp.path())); + let response = get(&app, "/projects/rad:z2u2CP3ZJzB7ZqE8jHrau19yjcfCQ").await; + + assert_eq!(response.status(), StatusCode::NOT_FOUND); + } + #[tokio::test] async fn test_projects_commits_root() { let tmp = tempfile::tempdir().unwrap();