diff --git a/Cargo.lock b/Cargo.lock index 60e7df698..bcee14a1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3898,6 +3898,7 @@ name = "radicle-types" version = "0.1.0" dependencies = [ "anyhow", + "axum", "base64 0.22.1", "localtime", "radicle", diff --git a/crates/radicle-types/Cargo.toml b/crates/radicle-types/Cargo.toml index 546160c04..10a5fb70e 100644 --- a/crates/radicle-types/Cargo.toml +++ b/crates/radicle-types/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] anyhow = { version = "1.0.90" } +axum = { version = "0.7.5", default-features = false, features = ["json"] } base64 = { version = "0.22.1" } radicle = { git = "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git" } radicle-surf = { version = "0.22.1", features = ["serde"] } diff --git a/crates/radicle-types/src/error.rs b/crates/radicle-types/src/error.rs index e7ea7624a..20df15a77 100644 --- a/crates/radicle-types/src/error.rs +++ b/crates/radicle-types/src/error.rs @@ -1,3 +1,6 @@ +use axum::body::Body; +use axum::http::{Response, StatusCode}; +use axum::response::IntoResponse; use serde::Serialize; #[derive(Debug, thiserror::Error)] @@ -108,6 +111,16 @@ impl Serialize for Error { } } +impl IntoResponse for Error { + fn into_response(self) -> Response
{ + ( + StatusCode::INTERNAL_SERVER_ERROR, + serde_json::to_string(&self).unwrap(), + ) + .into_response() + } +} + #[cfg(test)] #[allow(clippy::unwrap_used)] mod test { diff --git a/crates/test-http-api/src/api.rs b/crates/test-http-api/src/api.rs index ecabc88cc..bc7bbeaa8 100644 --- a/crates/test-http-api/src/api.rs +++ b/crates/test-http-api/src/api.rs @@ -15,6 +15,7 @@ use radicle::{git, identity}; use radicle_types as types; use radicle_types::cobs::issue::{Action, NewIssue}; use radicle_types::cobs::CobOptions; +use radicle_types::error::Error; use radicle_types::traits::auth::Auth; use radicle_types::traits::cobs::Cobs; use radicle_types::traits::issue::{Issues, IssuesMut}; @@ -23,8 +24,6 @@ use radicle_types::traits::repo::Repo; use radicle_types::traits::thread::Thread; use radicle_types::traits::Profile; -use crate::error::Error; - #[derive(Clone)] pub struct Context { profile: Arc