Fix send_bad_request

This commit is contained in:
flyingscorpio@clevo 2023-01-07 10:46:00 +01:00
parent 268d6c390b
commit 925ac6310c

View file

@ -2,8 +2,8 @@
use std::{fmt::Display, io::Write, net::TcpStream};
use serde_json::Value;
use serde::Serialize;
use serde_json::Value;
enum Status {
OK,
@ -48,11 +48,15 @@ impl<'a> Mouth<'a> {
}
/// Send BadRequest response to a client.
pub fn send_bad_request(&mut self, message: &str) {
let data: Value = if message.is_empty() {
pub fn send_bad_request<T>(&mut self, data: T)
where
T: Serialize,
{
let data = serde_json::json!(data);
let data = if data.eq("") {
serde_json::json!("La requête est mal formée, veuillez lire la documentation.")
} else {
serde_json::json!("")
data
};
self.send_data(
Status::BadRequest,