@nwire/errors 0.7.0 → 0.7.1
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 +0 -30
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -12,31 +12,6 @@ A small set of typed `Error` subclasses (`NotFoundError`, `ValidationError`, `Co
|
|
|
12
12
|
pnpm add @nwire/errors
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
## Standalone use
|
|
16
|
-
|
|
17
|
-
For developers who want typed domain errors in any TypeScript app — throw them anywhere, map them at the transport boundary, no Nwire stack required.
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { NotFoundError, ValidationError } from "@nwire/errors";
|
|
21
|
-
|
|
22
|
-
async function getCourse(id: string) {
|
|
23
|
-
const course = await db.courses.findFirst({ where: { id } });
|
|
24
|
-
if (!course) throw new NotFoundError("Course", id);
|
|
25
|
-
return course;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// In a custom Express handler:
|
|
29
|
-
app.get("/courses/:id", async (req, res) => {
|
|
30
|
-
try {
|
|
31
|
-
res.json(await getCourse(req.params.id));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
if (e instanceof NotFoundError)
|
|
34
|
-
return res.status(404).json({ code: e.code, message: e.message });
|
|
35
|
-
throw e;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
```
|
|
39
|
-
|
|
40
15
|
## Within nwire-app
|
|
41
16
|
|
|
42
17
|
For developers using this package as part of the Nwire stack. Throw from any handler / resolver / domain function; `@nwire/http` maps to HTTP status, queue maps to retry/DLQ decisions, CLI maps to exit code.
|
|
@@ -64,8 +39,3 @@ const getCourse = defineAction("getCourse", {
|
|
|
64
39
|
- `ConflictError(message)` — `code: "CONFLICT"` → HTTP 409.
|
|
65
40
|
- `ForbiddenError(message)` — `code: "FORBIDDEN"` → HTTP 403.
|
|
66
41
|
- `UnauthorizedError(message)` — `code: "UNAUTHORIZED"` → HTTP 401.
|
|
67
|
-
|
|
68
|
-
## See also
|
|
69
|
-
|
|
70
|
-
- [Architecture sketch §05 — Foundation tier](../../architecture-sketch.html#packages)
|
|
71
|
-
- Sibling packages: [@nwire/http](../nwire-http), [@nwire/forge](../nwire-forge)
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nwire/errors",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Typed domain errors (NotFoundError, ValidationError, ConflictError, ForbiddenError, UnauthorizedError) for uniform error handling. Use `instanceof` checks in route handlers instead of string comparisons.",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"files": [
|
|
6
7
|
"dist",
|
|
7
|
-
"README.md"
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE"
|
|
8
10
|
],
|
|
9
11
|
"type": "module",
|
|
10
12
|
"main": "./dist/errors.js",
|