add description to http errors
This commit is contained in:
parent
955aa9dfc6
commit
18b827690f
4 changed files with 24 additions and 6 deletions
|
|
@ -4,7 +4,7 @@ pub trait Request:
|
|||
Send + Sync + 'static + for<'de> serde::Deserialize<'de> + serde::Serialize
|
||||
{
|
||||
type Response: IsResponse;
|
||||
type Error: IsResponse;
|
||||
type Error: IsResponse + std::fmt::Display;
|
||||
}
|
||||
|
||||
eva::trait_set! {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use eva::{logging as log, perfect_derive, component_configs::ComponentConfig, supervisor::SlaveRx};
|
||||
use eva::{
|
||||
component_configs::ComponentConfig, logging as log, perfect_derive, supervisor::SlaveRx,
|
||||
};
|
||||
|
||||
use eyre::Context;
|
||||
use viendesu_core::{
|
||||
|
|
@ -23,14 +25,20 @@ pub trait Types: Send + Sync + 'static {
|
|||
type Service: Service + Clone;
|
||||
}
|
||||
|
||||
pub async fn serve(rx: SlaveRx, config: ComponentConfig<Config>, router: axum::Router) -> eyre::Result<()> {
|
||||
pub async fn serve(
|
||||
rx: SlaveRx,
|
||||
config: ComponentConfig<Config>,
|
||||
router: axum::Router,
|
||||
) -> eyre::Result<()> {
|
||||
// TODO: use it.
|
||||
_ = rx;
|
||||
let config::Config {
|
||||
unencrypted,
|
||||
ssl: _,
|
||||
} = &*config;
|
||||
let unencrypted = unencrypted.as_ref().expect("SSL-only currently is not supported");
|
||||
let unencrypted = unencrypted
|
||||
.as_ref()
|
||||
.expect("SSL-only currently is not supported");
|
||||
|
||||
if !unencrypted.enable {
|
||||
return Ok(());
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt;
|
||||
|
||||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response as AxumResponse},
|
||||
|
|
@ -17,10 +19,11 @@ macro_rules! header {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn err<E: IsResponse>(format: Format, error: E) -> AxumResponse {
|
||||
pub fn err<E: IsResponse + fmt::Display>(format: Format, error: E) -> AxumResponse {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Failure<E> {
|
||||
pub error: E,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
impl<T: HasStatusCode> HasStatusCode for Failure<T> {
|
||||
|
|
@ -29,7 +32,13 @@ pub fn err<E: IsResponse>(format: Format, error: E) -> AxumResponse {
|
|||
}
|
||||
}
|
||||
|
||||
respond(format, Failure { error })
|
||||
respond(
|
||||
format,
|
||||
Failure {
|
||||
description: error.to_string(),
|
||||
error,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue