@xbg.solutions/utils-errors 1.0.0
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/lib/app-errors.d.ts +49 -0
- package/lib/app-errors.d.ts.map +1 -0
- package/lib/app-errors.js +83 -0
- package/lib/app-errors.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/package.json +22 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application Error Classes
|
|
3
|
+
*
|
|
4
|
+
* Base error class and typed errors for the application.
|
|
5
|
+
* All errors extend AppError for consistent handling.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AppError extends Error {
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
readonly isOperational: boolean;
|
|
10
|
+
readonly details?: unknown;
|
|
11
|
+
constructor(statusCode: number, message: string, isOperational?: boolean, details?: unknown);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 400 Bad Request - Client sent invalid data
|
|
15
|
+
*/
|
|
16
|
+
export declare class ValidationError extends AppError {
|
|
17
|
+
constructor(message: string, details?: unknown);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 401 Unauthorized - Authentication required or failed
|
|
21
|
+
*/
|
|
22
|
+
export declare class UnauthorizedError extends AppError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 403 Forbidden - Authenticated but insufficient permissions
|
|
27
|
+
*/
|
|
28
|
+
export declare class ForbiddenError extends AppError {
|
|
29
|
+
constructor(message?: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 404 Not Found - Resource does not exist
|
|
33
|
+
*/
|
|
34
|
+
export declare class NotFoundError extends AppError {
|
|
35
|
+
constructor(resource: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 409 Conflict - Request conflicts with current state
|
|
39
|
+
*/
|
|
40
|
+
export declare class ConflictError extends AppError {
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 500 Internal Server Error - Unexpected server error
|
|
45
|
+
*/
|
|
46
|
+
export declare class InternalServerError extends AppError {
|
|
47
|
+
constructor(message?: string, details?: unknown);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=app-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-errors.d.ts","sourceRoot":"","sources":["../src/app-errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,aAAa,EAAE,OAAO,CAAC;IACvC,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;gBAGhC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,OAAc,EAC7B,OAAO,CAAC,EAAE,OAAO;CAcpB;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAI/C;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,GAAE,MAAuB;CAI7C;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,OAAO,GAAE,MAAoB;CAI1C;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,QAAQ,EAAE,MAAM;CAI7B;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,GAAE,MAAgC,EAAE,OAAO,CAAC,EAAE,OAAO;CAIzE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Application Error Classes
|
|
4
|
+
*
|
|
5
|
+
* Base error class and typed errors for the application.
|
|
6
|
+
* All errors extend AppError for consistent handling.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.InternalServerError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.ValidationError = exports.AppError = void 0;
|
|
10
|
+
class AppError extends Error {
|
|
11
|
+
constructor(statusCode, message, isOperational = true, details) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.isOperational = isOperational;
|
|
15
|
+
this.details = details;
|
|
16
|
+
// Maintains proper stack trace for where error was thrown (V8 only)
|
|
17
|
+
Error.captureStackTrace(this, this.constructor);
|
|
18
|
+
// Set the prototype explicitly (TypeScript requirement)
|
|
19
|
+
Object.setPrototypeOf(this, AppError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.AppError = AppError;
|
|
23
|
+
/**
|
|
24
|
+
* 400 Bad Request - Client sent invalid data
|
|
25
|
+
*/
|
|
26
|
+
class ValidationError extends AppError {
|
|
27
|
+
constructor(message, details) {
|
|
28
|
+
super(400, message, true, details);
|
|
29
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ValidationError = ValidationError;
|
|
33
|
+
/**
|
|
34
|
+
* 401 Unauthorized - Authentication required or failed
|
|
35
|
+
*/
|
|
36
|
+
class UnauthorizedError extends AppError {
|
|
37
|
+
constructor(message = 'Unauthorized') {
|
|
38
|
+
super(401, message, true);
|
|
39
|
+
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
43
|
+
/**
|
|
44
|
+
* 403 Forbidden - Authenticated but insufficient permissions
|
|
45
|
+
*/
|
|
46
|
+
class ForbiddenError extends AppError {
|
|
47
|
+
constructor(message = 'Forbidden') {
|
|
48
|
+
super(403, message, true);
|
|
49
|
+
Object.setPrototypeOf(this, ForbiddenError.prototype);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.ForbiddenError = ForbiddenError;
|
|
53
|
+
/**
|
|
54
|
+
* 404 Not Found - Resource does not exist
|
|
55
|
+
*/
|
|
56
|
+
class NotFoundError extends AppError {
|
|
57
|
+
constructor(resource) {
|
|
58
|
+
super(404, `${resource} not found`, true);
|
|
59
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.NotFoundError = NotFoundError;
|
|
63
|
+
/**
|
|
64
|
+
* 409 Conflict - Request conflicts with current state
|
|
65
|
+
*/
|
|
66
|
+
class ConflictError extends AppError {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super(409, message, true);
|
|
69
|
+
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ConflictError = ConflictError;
|
|
73
|
+
/**
|
|
74
|
+
* 500 Internal Server Error - Unexpected server error
|
|
75
|
+
*/
|
|
76
|
+
class InternalServerError extends AppError {
|
|
77
|
+
constructor(message = 'Internal server error', details) {
|
|
78
|
+
super(500, message, false, details);
|
|
79
|
+
Object.setPrototypeOf(this, InternalServerError.prototype);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.InternalServerError = InternalServerError;
|
|
83
|
+
//# sourceMappingURL=app-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-errors.js","sourceRoot":"","sources":["../src/app-errors.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,MAAa,QAAS,SAAQ,KAAK;IAKjC,YACE,UAAkB,EAClB,OAAe,EACf,gBAAyB,IAAI,EAC7B,OAAiB;QAEjB,KAAK,CAAC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CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;CACF;AALD,sCAKC;AAED;;GAEG;AACH,MAAa,aAAc,SAAQ,QAAQ;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;CACF;AALD,sCAKC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,QAAQ;IAC/C,YAAY,UAAkB,uBAAuB,EAAE,OAAiB;QACtE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACpC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;CACF;AALD,kDAKC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,aAAa,EACb,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error utilities barrel export
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InternalServerError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.ValidationError = exports.AppError = void 0;
|
|
7
|
+
var app_errors_1 = require("./app-errors");
|
|
8
|
+
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return app_errors_1.AppError; } });
|
|
9
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return app_errors_1.ValidationError; } });
|
|
10
|
+
Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return app_errors_1.UnauthorizedError; } });
|
|
11
|
+
Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return app_errors_1.ForbiddenError; } });
|
|
12
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return app_errors_1.NotFoundError; } });
|
|
13
|
+
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return app_errors_1.ConflictError; } });
|
|
14
|
+
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return app_errors_1.InternalServerError; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2CAQsB;AAPpB,sGAAA,QAAQ,OAAA;AACR,6GAAA,eAAe,OAAA;AACf,+GAAA,iBAAiB,OAAA;AACjB,4GAAA,cAAc,OAAA;AACd,2GAAA,aAAa,OAAA;AACb,2GAAA,aAAa,OAAA;AACb,iHAAA,mBAAmB,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xbg.solutions/utils-errors",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Custom error classes for the XBG backend",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": ["lib"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"build:watch": "tsc --watch",
|
|
11
|
+
"clean": "rm -rf lib",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {},
|
|
15
|
+
"devDependencies": {"@types/node": "^20.11.0", "typescript": "^5.3.3"},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "22"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
}
|
|
22
|
+
}
|