Browse Source
add api_not_found catcher for 404 errors in /api
pull/2768/head
Stefan Melmuk
3 years ago
No known key found for this signature in database
GPG Key ID: 817020C608FE9C09
3 changed files with
18 additions and
0 deletions
-
src/api/core/mod.rs
-
src/api/mod.rs
-
src/main.rs
|
|
@ -38,6 +38,7 @@ pub fn routes() -> Vec<Route> { |
|
|
|
// Move this somewhere else
|
|
|
|
//
|
|
|
|
use rocket::serde::json::Json; |
|
|
|
use rocket::Catcher; |
|
|
|
use rocket::Route; |
|
|
|
use serde_json::Value; |
|
|
|
|
|
|
@ -221,3 +222,18 @@ fn config() -> Json<Value> { |
|
|
|
}, |
|
|
|
})) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn catchers() -> Vec<Catcher> { |
|
|
|
catchers![api_not_found] |
|
|
|
} |
|
|
|
|
|
|
|
#[catch(404)] |
|
|
|
fn api_not_found() -> Json<Value> { |
|
|
|
Json(json!({ |
|
|
|
"error": { |
|
|
|
"code": 404, |
|
|
|
"reason": "Not Found", |
|
|
|
"description": "The requested resource could not be found." |
|
|
|
} |
|
|
|
})) |
|
|
|
} |
|
|
|
|
|
@ -10,6 +10,7 @@ use serde_json::Value; |
|
|
|
|
|
|
|
pub use crate::api::{ |
|
|
|
admin::routes as admin_routes, |
|
|
|
core::catchers as core_catchers, |
|
|
|
core::purge_sends, |
|
|
|
core::purge_trashed_ciphers, |
|
|
|
core::routes as core_routes, |
|
|
|
|
|
@ -426,6 +426,7 @@ async fn launch_rocket(pool: db::DbPool, extra_debug: bool) -> Result<(), Error> |
|
|
|
.mount([basepath, "/icons"].concat(), api::icons_routes()) |
|
|
|
.mount([basepath, "/notifications"].concat(), api::notifications_routes()) |
|
|
|
.register([basepath, "/"].concat(), api::web_catchers()) |
|
|
|
.register([basepath, "/api"].concat(), api::core_catchers()) |
|
|
|
.manage(pool) |
|
|
|
.manage(api::start_notification_server()) |
|
|
|
.attach(util::AppHeaders()) |
|
|
|