mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-10-18 19:10:45 +08:00
Fix error serialize in the test-http-api crate
This commit is contained in:
Generated
+1
@@ -3898,6 +3898,7 @@ name = "radicle-types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"axum",
|
||||
"base64 0.22.1",
|
||||
"localtime",
|
||||
"radicle",
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
@@ -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<Body> {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
serde_json::to_string(&self).unwrap(),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod test {
|
||||
|
||||
@@ -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<radicle::Profile>,
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::Json;
|
||||
use serde_json::json;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// radicle_types error.
|
||||
#[error(transparent)]
|
||||
Types(#[from] radicle_types::error::Error),
|
||||
}
|
||||
|
||||
impl IntoResponse for Error {
|
||||
fn into_response(self) -> Response {
|
||||
let (status, msg) = match self {
|
||||
other => {
|
||||
if cfg!(debug_assertions) {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, Some(other.to_string()))
|
||||
} else {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, None)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let body = Json(json!({
|
||||
"error": msg.or_else(|| status.canonical_reason().map(|r| r.to_string())),
|
||||
"code": status.as_u16()
|
||||
}));
|
||||
|
||||
(status, body).into_response()
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use tokio::net::TcpListener;
|
||||
use radicle::Profile;
|
||||
|
||||
mod api;
|
||||
mod error;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Options {
|
||||
|
||||
@@ -30,6 +30,6 @@ fn parse_options() -> Result<api::Options, lexopt::Error> {
|
||||
}
|
||||
}
|
||||
Ok(api::Options {
|
||||
listen: listen.unwrap_or_else(|| ([0, 0, 0, 0], 8080).into()),
|
||||
listen: listen.unwrap_or_else(|| ([0, 0, 0, 0], 8081).into()),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user