respect the config.api.METHOD config values
This commit is contained in:
parent
a10333ae16
commit
103c7c4c8d
|
@ -16,4 +16,11 @@ fn check_api_enabled(state: &SharedState) -> Result<(), WithStatus<Json>> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn function_disabled_err() -> WithStatus<Json> {
|
||||
warp::reply::with_status(
|
||||
json(&ErrorMessage::new(Error::APIFunctionDisabled)),
|
||||
StatusCode::SERVICE_UNAVAILABLE
|
||||
)
|
||||
}
|
||||
|
||||
pub mod get_all;
|
|
@ -2,11 +2,15 @@ use warp::{reply::{Reply, json}, reject::Rejection, Filter};
|
|||
|
||||
use crate::web::{state::SharedState, rejection::HttpReject};
|
||||
|
||||
use super::check_api_enabled;
|
||||
use super::{check_api_enabled, function_disabled_err};
|
||||
|
||||
pub async fn get_all(state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
||||
if let Err(res) = check_api_enabled(&state) {
|
||||
return Ok(Box::new(res));
|
||||
return Ok(Box::new(res))
|
||||
}
|
||||
|
||||
if ! state.config.api.get_all {
|
||||
return Ok(Box::new(function_disabled_err()))
|
||||
}
|
||||
|
||||
Ok(
|
||||
|
|
|
@ -3,6 +3,7 @@ use serde::{Serialize, Deserialize};
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum Error {
|
||||
APIDisabled,
|
||||
APIFunctionDisabled
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
@ -15,7 +16,8 @@ impl ErrorMessage {
|
|||
pub fn new(error: Error) -> ErrorMessage {
|
||||
ErrorMessage {
|
||||
details: match error {
|
||||
Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into())
|
||||
Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into()),
|
||||
Error::APIFunctionDisabled => Some("This API function is disabled by the administrator. Please contact them for further details.".into())
|
||||
},
|
||||
error,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue