diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs index f96f44b..eb58918 100644 --- a/src/error.rs +++ b/src/error.rs @@ -65,3 +65,16 @@ impl IntoResponse for ApiError { (status, Json(self)).into_response() } } + +/// The 401 every token-gated endpoint can return, as one shared +/// `IntoResponses` type (an `ApiError` body under the hood) instead of +/// writing out `(status = 401, description = "...", body = ApiError)` +/// by hand on each `#[utoipa::path(...)]` -- reference it bare inside +/// `responses(...)`, e.g. `responses(Unauthorized, (status = 200, ...))`. +/// Which endpoints actually need it (i.e. take `AuthToken`) is still a +/// per-handler decision; this only removes the repetition in +/// documenting the one response shape that decision implies. +#[derive(utoipa::IntoResponses)] +#[response(status = 401, description = "Missing or invalid token")] +#[allow(dead_code)] // only ever used for its OpenAPI schema, never constructed +pub struct Unauthorized(#[to_schema] ApiError); |
