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 <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
82a53e3a53
commit
c22bf8475a
|
|
@ -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}");
|
||||
|
|
|
|||
|
|
@ -2128,7 +2128,7 @@ mod routes {
|
|||
Some(Body::from(body)),
|
||||
Some(SESSION_ID.to_string()),
|
||||
)
|
||||
.await;
|
||||
.await;
|
||||
|
||||
assert_eq!(response.success().await, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue