mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Create new api_data module
This commit is contained in:
@ -1,57 +0,0 @@
|
||||
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 400 error
|
||||
pub fn bad_request(message: &str) -> HttpError {
|
||||
HttpError {
|
||||
error: InnerHTTPError {
|
||||
code: 400,
|
||||
message: message.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a 401 error
|
||||
pub fn forbidden(message: &str) -> HttpError {
|
||||
HttpError {
|
||||
error: InnerHTTPError {
|
||||
code: 401,
|
||||
message: message.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use crate::controllers::routes::RequestResult;
|
||||
use crate::data::http_error::HttpError;
|
||||
use std::error::Error;
|
||||
use serde::Serialize;
|
||||
use crate::data::error::{ResultBoxError, ExecError};
|
||||
@ -10,6 +9,7 @@ use actix_web::http::{HeaderName, HeaderValue};
|
||||
use std::str::FromStr;
|
||||
use crate::data::config::conf;
|
||||
use crate::data::api_client::APIClient;
|
||||
use crate::api_data::http_error::HttpError;
|
||||
|
||||
/// Http request handler
|
||||
///
|
||||
|
@ -1,7 +1,6 @@
|
||||
pub mod error;
|
||||
pub mod config;
|
||||
|
||||
pub mod http_error;
|
||||
pub mod http_request_handler;
|
||||
pub mod api_client;
|
||||
|
||||
|
Reference in New Issue
Block a user