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:
@ -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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user