add description to http errors
This commit is contained in:
parent
955aa9dfc6
commit
18b827690f
4 changed files with 24 additions and 6 deletions
|
|
@ -109,6 +109,7 @@ pub mod create {
|
||||||
|
|
||||||
#[data]
|
#[data]
|
||||||
pub enum Err {
|
pub enum Err {
|
||||||
|
#[display("{_0}")]
|
||||||
NoSuchBoard(#[from] errors::boards::NotFound),
|
NoSuchBoard(#[from] errors::boards::NotFound),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ pub trait Request:
|
||||||
Send + Sync + 'static + for<'de> serde::Deserialize<'de> + serde::Serialize
|
Send + Sync + 'static + for<'de> serde::Deserialize<'de> + serde::Serialize
|
||||||
{
|
{
|
||||||
type Response: IsResponse;
|
type Response: IsResponse;
|
||||||
type Error: IsResponse;
|
type Error: IsResponse + std::fmt::Display;
|
||||||
}
|
}
|
||||||
|
|
||||||
eva::trait_set! {
|
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 eyre::Context;
|
||||||
use viendesu_core::{
|
use viendesu_core::{
|
||||||
|
|
@ -23,14 +25,20 @@ pub trait Types: Send + Sync + 'static {
|
||||||
type Service: Service + Clone;
|
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.
|
// TODO: use it.
|
||||||
_ = rx;
|
_ = rx;
|
||||||
let config::Config {
|
let config::Config {
|
||||||
unencrypted,
|
unencrypted,
|
||||||
ssl: _,
|
ssl: _,
|
||||||
} = &*config;
|
} = &*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 {
|
if !unencrypted.enable {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{IntoResponse, Response as AxumResponse},
|
response::{IntoResponse, Response as AxumResponse},
|
||||||
|
|
@ -17,10 +19,11 @@ macro_rules! header {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[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)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct Failure<E> {
|
struct Failure<E> {
|
||||||
pub error: E,
|
pub error: E,
|
||||||
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: HasStatusCode> HasStatusCode for Failure<T> {
|
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]
|
#[track_caller]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue