1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Fix returned error in case of bad login tokens

This commit is contained in:
2020-05-24 18:33:47 +02:00
parent 399900077f
commit 89d5eac02b
2 changed files with 36 additions and 36 deletions

View File

@ -15,43 +15,33 @@ pub struct HttpError {
}
impl HttpError {
/// Generate a 404 error
pub fn not_found(message: &str) -> HttpError {
/// Construct a new custom error
pub fn new(code: u16, message: &str) -> HttpError {
HttpError {
error: InnerHTTPError {
code: 404,
code,
message: message.to_string(),
}
}
}
/// Generate a 404 error
pub fn not_found(message: &str) -> HttpError {
HttpError::new(404, message)
}
/// Generate a 500 error
pub fn internal_error(message: &str) -> HttpError {
HttpError {
error: InnerHTTPError {
code: 500,
message: message.to_string(),
}
}
HttpError::new(500, message)
}
/// Generate a 400 error
pub fn bad_request(message: &str) -> HttpError {
HttpError {
error: InnerHTTPError {
code: 400,
message: message.to_string(),
}
}
HttpError::new(400, message)
}
/// Generate a 401 error
pub fn forbidden(message: &str) -> HttpError {
HttpError {
error: InnerHTTPError {
code: 401,
message: message.to_string(),
}
}
HttpError::new(401, message)
}
}