From c22bf8475accca59b80ef4c1a08a9d763f3da686 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 26 Oct 2023 14:04:42 +0100 Subject: [PATCH] httpd: return the error message not found errors It's difficult to debug errors that mention a resource not being found, but not which resource was not found. Return the error message for not found variants. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-httpd/src/api/error.rs | 22 ++++++++++++++-------- radicle-httpd/src/api/v1/projects.rs | 2 +- radicle-httpd/src/test.rs | 12 ++++++++---- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index 6a9696fb..7d6792de 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -92,24 +92,30 @@ impl IntoResponse for Error { let message = self.to_string(); let (status, msg) = match self { Error::NotFound => (StatusCode::NOT_FOUND, None), - Error::CobStore(radicle::cob::store::Error::NotFound(_, _)) => { - (StatusCode::NOT_FOUND, None) + Error::CobStore(e @ radicle::cob::store::Error::NotFound(_, _)) => { + (StatusCode::NOT_FOUND, Some(e.to_string())) } Error::Auth(msg) => (StatusCode::BAD_REQUEST, Some(msg.to_string())), Error::Crypto(msg) => (StatusCode::BAD_REQUEST, Some(msg.to_string())), Error::Surf(radicle_surf::Error::Git(e)) if radicle::git::is_not_found_err(&e) => { - (StatusCode::NOT_FOUND, None) + (StatusCode::NOT_FOUND, Some(e.message().to_owned())) } Error::Surf(radicle_surf::Error::Directory( - radicle_surf::fs::error::Directory::PathNotFound(_), - )) => (StatusCode::NOT_FOUND, None), - Error::Git2(e) if radicle::git::is_not_found_err(&e) => (StatusCode::NOT_FOUND, None), + e @ radicle_surf::fs::error::Directory::PathNotFound(_), + )) => (StatusCode::NOT_FOUND, Some(e.to_string())), + Error::Git2(e) if radicle::git::is_not_found_err(&e) => { + (StatusCode::NOT_FOUND, Some(e.message().to_owned())) + } Error::Git2(e) => ( StatusCode::INTERNAL_SERVER_ERROR, Some(e.message().to_owned()), ), - Error::Storage(err) if err.is_not_found() => (StatusCode::NOT_FOUND, None), - Error::StorageRef(err) if err.is_not_found() => (StatusCode::NOT_FOUND, None), + Error::Storage(err) if err.is_not_found() => { + (StatusCode::NOT_FOUND, Some(err.to_string())) + } + Error::StorageRef(err) if err.is_not_found() => { + (StatusCode::NOT_FOUND, Some(err.to_string())) + } 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 1d885436..5e4af540 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -2128,7 +2128,7 @@ mod routes { Some(Body::from(body)), Some(SESSION_ID.to_string()), ) - .await; + .await; assert_eq!(response.success().await, true); diff --git a/radicle-httpd/src/test.rs b/radicle-httpd/src/test.rs index 39ac8732..1604f307 100644 --- a/radicle-httpd/src/test.rs +++ b/radicle-httpd/src/test.rs @@ -50,10 +50,14 @@ pub fn profile(home: &Path, seed: [u8; 32]) -> radicle::Profile { let keystore = Keystore::new(&home.keys()); let keypair = KeyPair::from_seed(Seed::from(seed)); let alias = node::Alias::new("seed"); - let storage = Storage::open(home.storage(), radicle::git::UserInfo { - alias: alias.clone(), - key: keypair.pk.into(), - }).unwrap(); + let storage = Storage::open( + home.storage(), + radicle::git::UserInfo { + alias: alias.clone(), + key: keypair.pk.into(), + }, + ) + .unwrap(); radicle::storage::git::transport::local::register(storage.clone()); keystore.store(keypair.clone(), "radicle", None).unwrap();