Add fmt options and move handlers
This commit is contained in:
parent
50bcac2a1b
commit
fdca5b7277
28 changed files with 85 additions and 70 deletions
emgauwa-core/src/handlers
38
emgauwa-core/src/handlers/mod.rs
Normal file
38
emgauwa-core/src/handlers/mod.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use actix_web::{error, Error, HttpRequest, HttpResponse};
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
pub(crate) mod errors;
|
||||
pub mod v1;
|
||||
|
||||
enum EmgauwaJsonPayLoadError {
|
||||
Error(error::JsonPayloadError),
|
||||
}
|
||||
|
||||
impl Serialize for EmgauwaJsonPayLoadError {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_struct("error", 3)?;
|
||||
s.serialize_field("type", "json-payload-error")?;
|
||||
s.serialize_field("code", &400)?;
|
||||
s.serialize_field(
|
||||
"description",
|
||||
&match self {
|
||||
EmgauwaJsonPayLoadError::Error(err) => format!("{}", err),
|
||||
},
|
||||
)?;
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn json_error_handler(err: error::JsonPayloadError, _: &HttpRequest) -> Error {
|
||||
error::InternalError::from_response(
|
||||
"",
|
||||
HttpResponse::BadRequest()
|
||||
.content_type("application/json")
|
||||
.json(EmgauwaJsonPayLoadError::Error(err)),
|
||||
)
|
||||
.into()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue