@lssm/lib.error 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217072406
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/dist/appError.js +20 -1
- package/dist/codes.js +22 -1
- package/dist/http.js +24 -1
- package/dist/index.js +5 -1
- package/package.json +3 -2
package/dist/appError.js
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/appError.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generic application error with code and optional details.
|
|
4
|
+
*/
|
|
5
|
+
var AppError = class extends Error {
|
|
6
|
+
constructor(code, message, details) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.details = details;
|
|
10
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
this.name = "AppError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Type guard to detect AppError */
|
|
15
|
+
function isAppError(err) {
|
|
16
|
+
return err instanceof AppError;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { AppError, isAppError };
|
package/dist/codes.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/codes.ts
|
|
2
|
+
/**
|
|
3
|
+
* Centralised error codes used across services.
|
|
4
|
+
* Extend this enum to add more domain-specific codes.
|
|
5
|
+
*/
|
|
6
|
+
let ErrorCode = /* @__PURE__ */ function(ErrorCode$1) {
|
|
7
|
+
ErrorCode$1["UNAUTHENTICATED"] = "UNAUTHENTICATED";
|
|
8
|
+
ErrorCode$1["FORBIDDEN"] = "FORBIDDEN";
|
|
9
|
+
ErrorCode$1["NOT_FOUND"] = "NOT_FOUND";
|
|
10
|
+
ErrorCode$1["INVALID_INPUT"] = "INVALID_INPUT";
|
|
11
|
+
ErrorCode$1["CONFLICT"] = "CONFLICT";
|
|
12
|
+
ErrorCode$1["RATE_LIMITED"] = "RATE_LIMITED";
|
|
13
|
+
ErrorCode$1["SERVER_ERROR"] = "SERVER_ERROR";
|
|
14
|
+
ErrorCode$1["POLICY_DENIED"] = "POLICY_DENIED";
|
|
15
|
+
return ErrorCode$1;
|
|
16
|
+
}({});
|
|
17
|
+
function isKnownErrorCode(code) {
|
|
18
|
+
return Object.values(ErrorCode).includes(code);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ErrorCode, isKnownErrorCode };
|
package/dist/http.js
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
import{ErrorCode
|
|
1
|
+
import { ErrorCode } from "./codes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/http.ts
|
|
4
|
+
/**
|
|
5
|
+
* Map known error codes to HTTP status codes.
|
|
6
|
+
*/
|
|
7
|
+
function httpStatus(code) {
|
|
8
|
+
switch (code) {
|
|
9
|
+
case ErrorCode.UNAUTHENTICATED: return 401;
|
|
10
|
+
case ErrorCode.FORBIDDEN:
|
|
11
|
+
case ErrorCode.POLICY_DENIED: return 403;
|
|
12
|
+
case ErrorCode.NOT_FOUND: return 404;
|
|
13
|
+
case ErrorCode.INVALID_INPUT: return 400;
|
|
14
|
+
case ErrorCode.CONFLICT: return 409;
|
|
15
|
+
case ErrorCode.RATE_LIMITED: return 429;
|
|
16
|
+
default: return 500;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert AppError or unknown error into a Problem JSON response body and status code.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { httpStatus };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import{ErrorCode
|
|
1
|
+
import { ErrorCode, isKnownErrorCode } from "./codes.js";
|
|
2
|
+
import { AppError, isAppError } from "./appError.js";
|
|
3
|
+
import { httpStatus } from "./http.js";
|
|
4
|
+
|
|
5
|
+
export { AppError, ErrorCode, httpStatus, isAppError, isKnownErrorCode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/lib.error",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251217072406",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
6
6
|
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"lint:check": "eslint src"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@lssm/tool.
|
|
17
|
+
"@lssm/tool.tsdown": "0.0.0-canary-20251217072406",
|
|
18
|
+
"@lssm/tool.typescript": "0.0.0-canary-20251217072406",
|
|
18
19
|
"tsdown": "^0.17.4",
|
|
19
20
|
"typescript": "^5.9.3"
|
|
20
21
|
},
|