1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2025-02-05 13:52:33 -06:00

Improve API error handling

This commit is contained in:
Solninja A 2024-12-31 19:54:22 +10:00
parent 5c2886f651
commit 1ef5d539d5

View file

@ -18,6 +18,7 @@ struct URLPair {
}
// Define JSON struct for response
// Named "ReturnResponse" rather than "Response" because of the previous import.
#[derive(Serialize)]
pub struct Response {
pub(crate) success: bool,
@ -46,10 +47,16 @@ pub fn is_api_ok(http: HttpRequest) -> Response {
let result = Response { success: false, error: false, reason: "Chhoto-Api-Key header not found".to_string(), pass: true };
result
}
} else {
// If the API key isn't set, but an API Key header is provided
if let Some(_) = auth::api_header(&http) {
let result = Response {success: false, error: true, reason: "API key access was attempted, but no API key is configured".to_string(), pass: false};
result
} else {
let result = Response {success: false, error: false, reason: "".to_string(), pass: true};
result
}
}
}