diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-03 13:14:47 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-03 13:14:47 +0000 |
| commit | 1f56f7fcbb0934ac8e2208401dc62102e9caa630 (patch) | |
| tree | bf51f2180a15cb0f9917f3bb4502a6db5f6ce760 | |
| parent | 0a21f4876c61894c788143db8c65c3d00525243b (diff) | |
| download | genenetwork4-1f56f7fcbb0934ac8e2208401dc62102e9caa630.tar.gz | |
Document ApiError 500 on / and /version, add README example.
* src/lib.rs (hello_world)[utoipa::path]<responses>: Add 500, body
ApiError.
(version)[utoipa::path]<responses>: Likewise. Neither handler has a
failure path today (no database access, no I/O); this documents the
same error contract as /species and /species/{species} in
/openapi.json for consistency.
* README.md: Add a second ApiError example with next omitted (null),
for an endpoint with no related endpoint to suggest. Note that
spec_url is always /openapi.json on every error from every endpoint,
and that / and /version document the 500 response without currently
having a way to produce one.
| -rw-r--r-- | README.md | 30 | ||||
| -rw-r--r-- | src/lib.rs | 6 |
2 files changed, 30 insertions, 6 deletions
diff --git a/README.md b/README.md index 9fed40e..784b9ed 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,13 @@ A Rust/Axum-based API server for GeneNetwork. ## Error handling -Every endpoint that can fail (currently `/species` and `/species/{species}`) -returns the same `ApiError` JSON shape on error, modeled on RFC 7807 -(Problem Details for HTTP APIs) plus a few extra fields (see `src/error.rs`): +Every endpoint uses the same `ApiError` JSON shape on error, modeled on +RFC 7807 (Problem Details for HTTP APIs) plus a few extra fields (see +`src/error.rs`). `/species` and `/species/{species}` can actually produce +one today (database errors, or a 404 for an unknown species); `/` and +`/version` document the same 500 response in `/openapi.json` for +consistency, even though neither has a failure path currently (no +database access, no I/O): ```json { @@ -76,9 +80,27 @@ returns the same `ApiError` JSON shape on error, modeled on RFC 7807 } ``` +`next` is omitted (`null`) when there's no obviously related endpoint to +suggest, e.g. a hypothetical error from `/`: + +```json +{ + "type": "/errors/internal_error", + "title": "Internal error", + "status": 500, + "code": "internal_error", + "detail": "example failure for /", + "operation_id": "hello_world", + "spec_url": "/openapi.json", + "request_id": "20974d91-52c0-41fe-ba2b-4df399a4cc4f", + "next": null +} +``` + - `type` and `spec_url` are relative paths, not absolute URLs, since this service has no fixed public domain; RFC 7807 explicitly allows `type` - to be a relative URI reference. + to be a relative URI reference. `spec_url` is always `/openapi.json`, + on every error from every endpoint. - `operation_id` is the OpenAPI operation that failed (same name as in `/openapi.json`). - `request_id` is the request's `x-request-id`, generated per request diff --git a/src/lib.rs b/src/lib.rs index aecdf36..37dd70c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,7 +44,8 @@ fn request_id_string(request_id: &RequestId) -> Option<String> { } #[utoipa::path(get, path = "/", responses( - (status = 200, description = "Greeting", body = String) + (status = 200, description = "Greeting", body = String), + (status = 500, description = "Internal error", body = ApiError) ))] async fn hello_world() -> &'static str { "Hello, world!" @@ -61,7 +62,8 @@ struct VersionInfo { } #[utoipa::path(get, path = "/version", responses( - (status = 200, description = "Build information", body = VersionInfo) + (status = 200, description = "Build information", body = VersionInfo), + (status = 500, description = "Internal error", body = ApiError) ))] async fn version() -> Json<VersionInfo> { Json(VersionInfo { |
