Fix send_bad_request
This commit is contained in:
parent
268d6c390b
commit
925ac6310c
1 changed files with 8 additions and 4 deletions
12
src/mouth.rs
12
src/mouth.rs
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue