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 message = self.to_string();
|
||||||
let (status, msg) = match self {
|
let (status, msg) = match self {
|
||||||
Error::NotFound => (StatusCode::NOT_FOUND, None),
|
Error::NotFound => (StatusCode::NOT_FOUND, None),
|
||||||
Error::CobStore(radicle::cob::store::Error::NotFound(_, _)) => {
|
Error::CobStore(e @ radicle::cob::store::Error::NotFound(_, _)) => {
|
||||||
(StatusCode::NOT_FOUND, None)
|
(StatusCode::NOT_FOUND, Some(e.to_string()))
|
||||||
}
|
}
|
||||||
Error::Auth(msg) => (StatusCode::BAD_REQUEST, Some(msg.to_string())),
|
Error::Auth(msg) => (StatusCode::BAD_REQUEST, Some(msg.to_string())),
|
||||||
Error::Crypto(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) => {
|
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(
|
Error::Surf(radicle_surf::Error::Directory(
|
||||||
radicle_surf::fs::error::Directory::PathNotFound(_),
|
e @ radicle_surf::fs::error::Directory::PathNotFound(_),
|
||||||
)) => (StatusCode::NOT_FOUND, None),
|
)) => (StatusCode::NOT_FOUND, Some(e.to_string())),
|
||||||
Error::Git2(e) if radicle::git::is_not_found_err(&e) => (StatusCode::NOT_FOUND, None),
|
Error::Git2(e) if radicle::git::is_not_found_err(&e) => {
|
||||||
|
(StatusCode::NOT_FOUND, Some(e.message().to_owned()))
|
||||||
|
}
|
||||||
Error::Git2(e) => (
|
Error::Git2(e) => (
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Some(e.message().to_owned()),
|
Some(e.message().to_owned()),
|
||||||
),
|
),
|
||||||
Error::Storage(err) if err.is_not_found() => (StatusCode::NOT_FOUND, None),
|
Error::Storage(err) if err.is_not_found() => {
|
||||||
Error::StorageRef(err) if err.is_not_found() => (StatusCode::NOT_FOUND, None),
|
(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)),
|
Error::BadRequest(msg) => (StatusCode::BAD_REQUEST, Some(msg)),
|
||||||
other => {
|
other => {
|
||||||
tracing::error!("Error: {message}");
|
tracing::error!("Error: {message}");
|
||||||
|
|
|
||||||
|
|
@ -2128,7 +2128,7 @@ mod routes {
|
||||||
Some(Body::from(body)),
|
Some(Body::from(body)),
|
||||||
Some(SESSION_ID.to_string()),
|
Some(SESSION_ID.to_string()),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
assert_eq!(response.success().await, true);
|
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 keystore = Keystore::new(&home.keys());
|
||||||
let keypair = KeyPair::from_seed(Seed::from(seed));
|
let keypair = KeyPair::from_seed(Seed::from(seed));
|
||||||
let alias = node::Alias::new("seed");
|
let alias = node::Alias::new("seed");
|
||||||
let storage = Storage::open(home.storage(), radicle::git::UserInfo {
|
let storage = Storage::open(
|
||||||
alias: alias.clone(),
|
home.storage(),
|
||||||
key: keypair.pk.into(),
|
radicle::git::UserInfo {
|
||||||
}).unwrap();
|
alias: alias.clone(),
|
||||||
|
key: keypair.pk.into(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
radicle::storage::git::transport::local::register(storage.clone());
|
radicle::storage::git::transport::local::register(storage.clone());
|
||||||
keystore.store(keypair.clone(), "radicle", None).unwrap();
|
keystore.store(keypair.clone(), "radicle", None).unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue