@lssm/lib.error 1.7.4 → 1.9.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 ADDED
@@ -0,0 +1,54 @@
1
+ # @lssm/lib.error
2
+
3
+ Standardized error handling primitives for LSSM applications.
4
+
5
+ ## Purpose
6
+
7
+ To provide a consistent error model across the monorepo, enabling predictable error handling, serialization, and mapping to HTTP status codes and GraphQL errors.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @lssm/lib.error
13
+ # or
14
+ bun add @lssm/lib.error
15
+ ```
16
+
17
+ ## Key Concepts
18
+
19
+ - **AppError**: Base class for all application errors, carrying a `code` and optional `meta` data.
20
+ - **Error Codes**: Centralized enum/registry of error codes (e.g., `NOT_FOUND`, `UNAUTHORIZED`).
21
+ - **HTTP Mapping**: Utilities to map error codes to HTTP status codes (e.g., `NOT_FOUND` -> 404).
22
+
23
+ ## Exports
24
+
25
+ - `AppError`: The base error class.
26
+ - `codes`: Error code definitions.
27
+ - `http`: HTTP status code helpers.
28
+
29
+ ## Usage
30
+
31
+ ```ts
32
+ import { AppError, ErrorCode } from '@lssm/lib.error';
33
+
34
+ // Throwing a known error
35
+ throw new AppError(ErrorCode.NOT_FOUND, 'User not found', { userId: 123 });
36
+
37
+ // Catching and handling
38
+ try {
39
+ // ...
40
+ } catch (err) {
41
+ if (err instanceof AppError) {
42
+ console.log(err.code); // 'NOT_FOUND'
43
+ console.log(err.meta); // { userId: 123 }
44
+ }
45
+ }
46
+ ```
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","names":[],"sources":["../src/http.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;iBAAgB,UAAA,OAAiB"}
1
+ {"version":3,"file":"http.d.ts","names":[],"sources":["../src/http.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;iBAAgB,UAAA,OAAiB"}
package/dist/http.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","names":[],"sources":["../src/http.ts"],"sourcesContent":["import { isAppError } from './appError';\nimport { ErrorCode } from './codes';\n\n/**\n * Map known error codes to HTTP status codes.\n */\nexport function httpStatus(code: ErrorCode): number {\n switch (code) {\n case ErrorCode.UNAUTHENTICATED:\n return 401;\n case ErrorCode.FORBIDDEN:\n case ErrorCode.POLICY_DENIED:\n return 403;\n case ErrorCode.NOT_FOUND:\n return 404;\n case ErrorCode.INVALID_INPUT:\n return 400;\n case ErrorCode.CONFLICT:\n return 409;\n case ErrorCode.RATE_LIMITED:\n return 429;\n default:\n return 500;\n }\n}\n\n/**\n * Convert AppError or unknown error into a Problem JSON response body and status code.\n */\n// export function toHttpResponse(err: unknown): { status: number; body: any } {\n// if (isAppError(err)) {\n// const status = httpStatus(err.code);\n// return {\n// status,\n// body: {\n// type: `https://api.chaman.dev/errors/${err.code.toLowerCase()}`,\n// title: err.message,\n// detail: err.details ?? null,\n// status,\n// },\n// };\n// }\n// // Unknown error: hide internal details\n// return {\n// status: 500,\n// body: {\n// type: 'https://api.chaman.dev/errors/server_error',\n// title: 'Unexpected Error',\n// detail: null,\n// status: 500,\n// },\n// };\n// }\n"],"mappings":"uCAMA,SAAgB,EAAW,EAAyB,CAClD,OAAQ,EAAR,CACE,KAAK,EAAU,gBACb,MAAO,KACT,KAAK,EAAU,UACf,KAAK,EAAU,cACb,MAAO,KACT,KAAK,EAAU,UACb,MAAO,KACT,KAAK,EAAU,cACb,MAAO,KACT,KAAK,EAAU,SACb,MAAO,KACT,KAAK,EAAU,aACb,MAAO,KACT,QACE,MAAO"}
1
+ {"version":3,"file":"http.js","names":[],"sources":["../src/http.ts"],"sourcesContent":["import { ErrorCode } from './codes';\n\n/**\n * Map known error codes to HTTP status codes.\n */\nexport function httpStatus(code: ErrorCode): number {\n switch (code) {\n case ErrorCode.UNAUTHENTICATED:\n return 401;\n case ErrorCode.FORBIDDEN:\n case ErrorCode.POLICY_DENIED:\n return 403;\n case ErrorCode.NOT_FOUND:\n return 404;\n case ErrorCode.INVALID_INPUT:\n return 400;\n case ErrorCode.CONFLICT:\n return 409;\n case ErrorCode.RATE_LIMITED:\n return 429;\n default:\n return 500;\n }\n}\n\n/**\n * Convert AppError or unknown error into a Problem JSON response body and status code.\n */\n// export function toHttpResponse(err: unknown): { status: number; body: any } {\n// if (isAppError(err)) {\n// const status = httpStatus(err.code);\n// return {\n// status,\n// body: {\n// type: `https://api.chaman.dev/errors/${err.code.toLowerCase()}`,\n// title: err.message,\n// detail: err.details ?? null,\n// status,\n// },\n// };\n// }\n// // Unknown error: hide internal details\n// return {\n// status: 500,\n// body: {\n// type: 'https://api.chaman.dev/errors/server_error',\n// title: 'Unexpected Error',\n// detail: null,\n// status: 500,\n// },\n// };\n// }\n"],"mappings":"uCAKA,SAAgB,EAAW,EAAyB,CAClD,OAAQ,EAAR,CACE,KAAK,EAAU,gBACb,MAAO,KACT,KAAK,EAAU,UACf,KAAK,EAAU,cACb,MAAO,KACT,KAAK,EAAU,UACb,MAAO,KACT,KAAK,EAAU,cACb,MAAO,KACT,KAAK,EAAU,SACb,MAAO,KACT,KAAK,EAAU,aACb,MAAO,KACT,QACE,MAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lssm/lib.error",
3
- "version": "1.7.4",
3
+ "version": "1.9.1",
4
4
  "scripts": {
5
5
  "build": "bun build:bundle && bun build:types",
6
6
  "build:bundle": "tsdown",
@@ -13,14 +13,14 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@lssm/tool.typescript": "*",
16
- "tsdown": "^0.15.9",
16
+ "tsdown": "^0.16.6",
17
17
  "typescript": "^5.9.3"
18
18
  },
19
19
  "dependencies": {},
20
20
  "peerDependencies": {
21
21
  "elysia": "^1.4.11",
22
22
  "express": "^5.1.0",
23
- "next": "15.5.6"
23
+ "next": "16.0.3"
24
24
  },
25
25
  "type": "module",
26
26
  "main": "./dist/index.js",