Skip to main content

docspec_http/handlers/
fallback.rs

1//! Fallback handlers for unmatched routes and disallowed methods.
2
3use axum::http::{Method, Uri};
4
5use crate::error::HttpError;
6
7/// Fallback handler that returns RFC 7807 Problem JSON for all unmatched routes.
8///
9/// Uses only [`Uri::path`] (not the full URI) to avoid leaking sensitive query
10/// parameters in error responses.
11#[inline]
12#[must_use]
13// Reason: Axum handlers must be async to satisfy the Handler trait, even if they don't await.
14#[allow(clippy::unused_async)]
15pub async fn not_found(request_uri: Uri, method: Method) -> HttpError {
16    HttpError::NotFound {
17        method: method.to_string(),
18        path: request_uri.path().to_owned(),
19    }
20}
21
22/// Fallback handler for wrong HTTP methods on `/conversion`.
23///
24/// Returns 405 Method Not Allowed with `Allow: POST, OPTIONS`.
25#[inline]
26#[must_use]
27// Reason: Axum handlers must be async to satisfy the Handler trait, even if they don't await.
28#[allow(clippy::unused_async)]
29pub async fn conversion_method_not_allowed() -> HttpError {
30    HttpError::MethodNotAllowed {
31        allowed: "POST, OPTIONS",
32    }
33}
34
35/// Fallback handler for wrong HTTP methods on `/health`.
36///
37/// Returns 405 Method Not Allowed with `Allow: GET, HEAD, OPTIONS`.
38#[inline]
39#[must_use]
40// Reason: Axum handlers must be async to satisfy the Handler trait, even if they don't await.
41#[allow(clippy::unused_async)]
42pub async fn health_method_not_allowed() -> HttpError {
43    HttpError::MethodNotAllowed {
44        allowed: "GET, HEAD, OPTIONS",
45    }
46}