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