mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 19:30:38 +08:00
A new `invoke` function calls either the tauri backend or the `test-http-api` function if ran in a browser.
33 lines
878 B
Rust
33 lines
878 B
Rust
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()
|
|
}
|
|
}
|