You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document the standard error response envelope for Nerva APIs: the
error code registry and constants pattern, typed AppError classes,
global handling via app.onError() and app.notFound(), per-category
examples (400/401/403/404/409/429/500), and the mapping to RFC 9457
Problem Details. Update the standards README to the nested envelope
shape and link the guide.
Closes#56
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
thrownewHTTPException(404, { message: "Todo not found" });
112
+
thrownewNotFoundError("Todo", id);
113
113
}
114
114
115
-
// Global error handler in app setup
116
-
app.onError((err, c) => {
117
-
if (errinstanceofHTTPException) {
118
-
returnc.json({ error: err.message }, err.status);
119
-
}
120
-
console.error(err);
121
-
returnc.json({ error: "Internal server error" }, 500);
122
-
});
115
+
// Global error handler in app setup -- serializes AppError, ZodError,
116
+
// HTTPException, and unexpected errors to the standard envelope
117
+
app.onError(errorHandler);
123
118
```
124
119
125
120
### Context Typing
@@ -323,15 +318,17 @@ See the [CORS configuration guide](./cors-configuration.md) for environment-spec
323
318
324
319
### Consistent Response Format
325
320
326
-
All error responses follow the same shape:
321
+
All error responses follow the same shape -- a single top-level `error` object:
327
322
328
323
```json
329
324
{
330
-
"error": "Validation failed",
331
-
"code": "VALIDATION_ERROR",
332
-
"details": [
333
-
{ "field": "title", "message": "Required" }
334
-
]
325
+
"error": {
326
+
"code": "VALIDATION_ERROR",
327
+
"message": "Request validation failed",
328
+
"details": [
329
+
{ "field": "title", "message": "Required" }
330
+
]
331
+
}
335
332
}
336
333
```
337
334
@@ -344,9 +341,12 @@ All error responses follow the same shape:
344
341
|`FORBIDDEN`| 403 | Authenticated but insufficient permissions |
345
342
|`NOT_FOUND`| 404 | Resource does not exist |
346
343
|`CONFLICT`| 409 | Duplicate resource or state conflict |
344
+
|`PAYLOAD_TOO_LARGE`| 413 | Request body exceeds the size limit |
347
345
|`RATE_LIMITED`| 429 | Too many requests |
348
346
|`INTERNAL_ERROR`| 500 | Unexpected server error |
349
347
348
+
See the [error handling guide](./error-handling.md) for the full format definition, error code constants, typed error classes, the global `app.onError()` handler, per-category examples, and how the format maps to RFC 9457 Problem Details.
0 commit comments