1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-28 00:09:21 +00:00
comunicapiv3/src/data/http_error.rs

47 lines
993 B
Rust

use serde::Serialize;
/// HTTP request error
///
/// @author Pierre Hubert
#[derive(Serialize)]
pub struct InnerHTTPError {
pub code: u16,
pub message: String,
}
#[derive(Serialize)]
pub struct HttpError {
pub error: InnerHTTPError
}
impl HttpError {
/// Generate a 404 error
pub fn not_found(message: &str) -> HttpError {
HttpError {
error: InnerHTTPError {
code: 404,
message: message.to_string(),
}
}
}
/// Generate a 500 error
pub fn internal_error(message: &str) -> HttpError {
HttpError {
error: InnerHTTPError {
code: 500,
message: message.to_string(),
}
}
}
/// Generate a 401 error
pub fn bad_request(message: &str) -> HttpError {
HttpError {
error: InnerHTTPError {
code: 401,
message: message.to_string(),
}
}
}
}