@rexezuge/errors 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @rexezuge/errors
|
|
2
|
+
|
|
3
|
+
Catalog-driven HTTP/service error taxonomy with retry markers and wire envelopes for the Rexezuge-CloudflareWorkers family.
|
|
4
|
+
|
|
5
|
+
Zero dependencies. Every boundary in the family (route handlers, middleware, background tasks) branches on `instanceof ServiceError`, so this package sits at the bottom of the dependency graph: `d1`, `identity`, and `web` all import it.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @rexezuge/errors
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 1. The taxonomy
|
|
14
|
+
|
|
15
|
+
`ServiceError` is the abstract root. Status, machine `type`, `retryable`, and `expose` are public fields fixed at construction — callers read them far more often than they are written.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { NotFoundError, ServiceError } from '@rexezuge/errors';
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await loadFile(id);
|
|
22
|
+
} catch (error: unknown) {
|
|
23
|
+
const normalized = ServiceError.from(error); // ServiceError passes through; anything else becomes a 500
|
|
24
|
+
return Response.json(normalized.toErrorResponse().body, { status: normalized.status });
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`toErrorResponse()` returns `{ status, body }` in the family envelope `{ Exception: { Type, Message } }`. A non-exposing error (5xx) has its message substituted with a generic one — the real message is for operators, never clients.
|
|
29
|
+
|
|
30
|
+
## 2. Status classes
|
|
31
|
+
|
|
32
|
+
One class per row of `CATALOG`, so a status can never disagree with its code or default message:
|
|
33
|
+
|
|
34
|
+
| Class | Status | Exposes message |
|
|
35
|
+
| --- | --- | --- |
|
|
36
|
+
| `BadRequestError` | 400 | yes |
|
|
37
|
+
| `UnauthorizedError` | 401 | yes |
|
|
38
|
+
| `ForbiddenError` | 403 | yes |
|
|
39
|
+
| `NotFoundError` | 404 | yes |
|
|
40
|
+
| `MethodNotAllowedError` | 405 | yes |
|
|
41
|
+
| `ConflictError` | 409 | yes |
|
|
42
|
+
| `PreconditionFailedError` | 412 | yes |
|
|
43
|
+
| `PayloadTooLargeError` | 413 | yes |
|
|
44
|
+
| `UnsupportedMediaTypeError` | 415 | yes |
|
|
45
|
+
| `RateLimitedError` | 429 | yes |
|
|
46
|
+
| `InternalServerError` | 500 | no |
|
|
47
|
+
| `NotImplementedError` | 501 | no |
|
|
48
|
+
| `BadGatewayError` | 502 | no |
|
|
49
|
+
| `ServiceUnavailableError` | 503 | yes |
|
|
50
|
+
| `DatabaseError` | 502 | no |
|
|
51
|
+
|
|
52
|
+
`HttpServiceError` is the generic carrier when only a catalog entry is needed. `DatabaseError` carries the D1 classifier's verdict in its `retryable` flag.
|
|
53
|
+
|
|
54
|
+
## 3. Outcome errors
|
|
55
|
+
|
|
56
|
+
When only the throwing code knows whether a retry could help (OAuth grant revoked vs. provider throttling), it says so explicitly:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { NonRetryableError, RetryableError } from '@rexezuge/errors';
|
|
60
|
+
|
|
61
|
+
throw new RetryableError('Provider throttled us'); // 502, retryable
|
|
62
|
+
throw new NonRetryableError('Grant revoked'); // 400, not retryable
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`ProviderApiRetryableError` / `ProviderApiNonRetryableError` and `OAuth2TokenRetryableError` / `OAuth2TokenNonRetryableError` are the domain aliases. Subclasses must genuinely `extend` — an `implements` breaks the `instanceof` chain and masks typed errors as generic 500s.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Verifying this package
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm --filter @rexezuge/errors exec tsc -p tsconfig.json
|
|
73
|
+
pnpm --filter @rexezuge/errors typecheck
|
|
74
|
+
pnpm --filter @rexezuge/errors test
|
|
75
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexezuge/errors",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"typescript": "6.0.3",
|
|
30
30
|
"vitest": "4.1.11"
|
|
31
31
|
},
|
|
32
|
+
"description": "Catalog-driven HTTP/service error taxonomy with retry markers and wire envelopes for the Rexezuge-CloudflareWorkers family.",
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsc -p tsconfig.json",
|
|
34
35
|
"typecheck": "tsc -p tsconfig.test.json --noEmit",
|