@atlantjs/backend 4.0.14 → 4.0.15
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlantjs/backend",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.15",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"express": "4.19.2",
|
|
39
39
|
"helmet": "7.1.0",
|
|
40
40
|
"inversify": "6.0.2",
|
|
41
|
+
"lodash": "^4.17.21",
|
|
41
42
|
"module-alias": "2.2.3",
|
|
42
43
|
"reflect-metadata": "0.2.2",
|
|
43
44
|
"routing-controllers": "0.10.4",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"@types/cookie-parser": "1.4.8",
|
|
50
51
|
"@types/cors": "2.8.17",
|
|
51
52
|
"@types/express": "5.0.0",
|
|
53
|
+
"@types/lodash": "^4.17.16",
|
|
52
54
|
"@types/node": "22.13.5",
|
|
53
55
|
"copyfiles": "2.4.1",
|
|
54
56
|
"cross-env": "7.0.3",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ErrorRequestHandler, NextFunction, Request, Response } from "express";
|
|
2
2
|
export declare class DefaultErrorHandlerMiddleware {
|
|
3
3
|
static create(): ErrorRequestHandler;
|
|
4
|
-
use(error: Error,
|
|
4
|
+
use(error: Error, req: Request, res: Response, next: NextFunction): void;
|
|
5
5
|
private handleError;
|
|
6
6
|
private handleExceptions;
|
|
7
7
|
private logUnhandledError;
|
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.DefaultErrorHandlerMiddleware = void 0;
|
|
4
|
-
const
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
5
8
|
const routing_controllers_1 = require("routing-controllers");
|
|
9
|
+
const unknow_error_1 = require("./unknow.error");
|
|
10
|
+
const arch_1 = require("@atlantjs/arch");
|
|
6
11
|
class DefaultErrorHandlerMiddleware {
|
|
7
12
|
static create() {
|
|
8
13
|
const middleware = new DefaultErrorHandlerMiddleware();
|
|
9
|
-
return (error,
|
|
14
|
+
return (error, req, res, next) => middleware.use(error, req, res, next);
|
|
10
15
|
}
|
|
11
|
-
use(error,
|
|
12
|
-
if (
|
|
16
|
+
use(error, req, res, next) {
|
|
17
|
+
if (res.headersSent) {
|
|
13
18
|
next(error);
|
|
14
19
|
return;
|
|
15
20
|
}
|
|
16
|
-
this.handleError(error,
|
|
21
|
+
this.handleError(error, res);
|
|
17
22
|
}
|
|
18
|
-
handleError(error,
|
|
23
|
+
handleError(error, res) {
|
|
19
24
|
if (!(error instanceof routing_controllers_1.HttpError)) {
|
|
20
|
-
this.handleExceptions(error,
|
|
25
|
+
this.handleExceptions(error, res);
|
|
21
26
|
return;
|
|
22
27
|
}
|
|
23
28
|
if (error.httpCode < arch_1.HttpStatusCodes.INTERNAL_SERVER_ERROR) {
|
|
24
|
-
|
|
29
|
+
res.status(error.httpCode).send(lodash_1.default.omit(error, "httpCode"));
|
|
25
30
|
return;
|
|
26
31
|
}
|
|
27
|
-
|
|
32
|
+
res.status(error.httpCode).send({
|
|
28
33
|
code: arch_1.HttpStatusCodes[error.httpCode].toLocaleLowerCase(),
|
|
29
34
|
message: arch_1.HttpStatusCodes[error.httpCode],
|
|
30
35
|
});
|
|
31
36
|
}
|
|
32
|
-
handleExceptions(error,
|
|
37
|
+
handleExceptions(error, res) {
|
|
33
38
|
this.logUnhandledError(error);
|
|
34
|
-
|
|
39
|
+
res.status(arch_1.HttpStatusCodes.INTERNAL_SERVER_ERROR).send(new unknow_error_1.UnknownError({
|
|
35
40
|
code: "internal_error",
|
|
36
41
|
message: "Internal server error",
|
|
37
|
-
});
|
|
42
|
+
}));
|
|
38
43
|
}
|
|
39
44
|
logUnhandledError(error) {
|
|
40
|
-
console.error("\
|
|
45
|
+
console.error("\n⚠️ Unhandled request error", {
|
|
41
46
|
error,
|
|
42
47
|
});
|
|
43
48
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface UnknownApplicationError {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class UnknownError {
|
|
6
|
+
readonly unknownCode: string;
|
|
7
|
+
readonly unknownMessage: string;
|
|
8
|
+
constructor(error: UnknownApplicationError);
|
|
9
|
+
toPlain(): unknown;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UnknownError = void 0;
|
|
13
|
+
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
class UnknownError {
|
|
15
|
+
constructor(error) {
|
|
16
|
+
this.unknownCode = error.code;
|
|
17
|
+
this.unknownMessage = error.message;
|
|
18
|
+
}
|
|
19
|
+
toPlain() {
|
|
20
|
+
return (0, class_transformer_1.instanceToPlain)(this);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.UnknownError = UnknownError;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, class_transformer_1.Expose)(),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], UnknownError.prototype, "unknownCode", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_transformer_1.Expose)(),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], UnknownError.prototype, "unknownMessage", void 0);
|