framework-do-dede 0.0.38 → 0.0.39
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/handlers/controller.handler.js +6 -11
- package/dist/http/HttpServer.d.ts +2 -1
- package/dist/http/HttpServer.js +11 -18
- package/dist/http/ServerError.d.ts +5 -0
- package/dist/http/ServerError.js +10 -0
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +2 -2
- package/dist/protocols/RequestMetrics.d.ts +1 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Registry } from "../di/registry";
|
|
2
|
-
import {
|
|
2
|
+
import { InternalServerError } from "../http";
|
|
3
3
|
export default class ControllerHandler {
|
|
4
4
|
constructor(httpServer, port) {
|
|
5
5
|
for (const { instance, instanceMethod, middlewares, method, route, statusCode, params, query, validation, offLogs, metricsHandlers } of this.registryControllers()) {
|
|
@@ -56,8 +56,9 @@ export default class ControllerHandler {
|
|
|
56
56
|
catch (error) {
|
|
57
57
|
if (!offLogs)
|
|
58
58
|
console.log('\x1b[31m%s\x1b[0m', `❌ [LOG] Erro: "${logger.handler.instance}.${logger.handler.method}:" - error: ${error.message}`);
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const capturedError = this.extractError(error);
|
|
60
|
+
requestMetrics.error = capturedError;
|
|
61
|
+
return capturedError;
|
|
61
62
|
}
|
|
62
63
|
finally {
|
|
63
64
|
requestMetrics.endTime = performance.now();
|
|
@@ -122,16 +123,10 @@ export default class ControllerHandler {
|
|
|
122
123
|
return filter;
|
|
123
124
|
}
|
|
124
125
|
extractError(error) {
|
|
125
|
-
let statusCode;
|
|
126
|
-
if (error instanceof ServerError)
|
|
127
|
-
statusCode = error.getStatusCode();
|
|
128
|
-
else
|
|
129
|
-
statusCode = 500;
|
|
130
126
|
return {
|
|
131
|
-
stack: error.stack?.toString(),
|
|
132
|
-
originalMessage: error.message,
|
|
133
127
|
message: error.message,
|
|
134
|
-
statusCode
|
|
128
|
+
statusCode: error.getStatusCode(),
|
|
129
|
+
unexpectedError: error instanceof InternalServerError ? error.getUnexpectedError() : undefined,
|
|
135
130
|
};
|
|
136
131
|
}
|
|
137
132
|
}
|
|
@@ -19,10 +19,11 @@ type FrameworkWeb = {
|
|
|
19
19
|
export default abstract class HttpServer {
|
|
20
20
|
protected framework: FrameworkWeb;
|
|
21
21
|
protected frameworkName: string;
|
|
22
|
-
|
|
22
|
+
private defaultMessageError;
|
|
23
23
|
constructor(framework: FrameworkWeb, frameworkName: 'elysia' | 'express');
|
|
24
24
|
use(middleware: CallableFunction): HttpServer;
|
|
25
25
|
register(httpServerParams: HttpServerParams, handler: CallableFunction): void;
|
|
26
|
+
setDefaultMessageError(message: string): void;
|
|
26
27
|
listen(port: number): void;
|
|
27
28
|
private mountRoute;
|
|
28
29
|
private elysia;
|
package/dist/http/HttpServer.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FrameworkError } from "./FrameworkError";
|
|
2
|
-
import { ServerError } from "./ServerError";
|
|
2
|
+
import { InternalServerError, ServerError } from "./ServerError";
|
|
3
3
|
export default class HttpServer {
|
|
4
4
|
framework;
|
|
5
5
|
frameworkName;
|
|
6
|
-
defaultMessageError = '
|
|
6
|
+
defaultMessageError = '';
|
|
7
7
|
constructor(framework, frameworkName) {
|
|
8
8
|
if (frameworkName !== 'elysia' && frameworkName !== 'express')
|
|
9
9
|
throw new FrameworkError('Framework not supported');
|
|
@@ -20,6 +20,9 @@ export default class HttpServer {
|
|
|
20
20
|
return this.elysia(httpServerParams, route, handler);
|
|
21
21
|
return this.express(httpServerParams, route, handler);
|
|
22
22
|
}
|
|
23
|
+
setDefaultMessageError(message) {
|
|
24
|
+
this.defaultMessageError = message;
|
|
25
|
+
}
|
|
23
26
|
listen(port) {
|
|
24
27
|
this.framework.listen(port);
|
|
25
28
|
}
|
|
@@ -50,16 +53,10 @@ export default class HttpServer {
|
|
|
50
53
|
catch (error) {
|
|
51
54
|
if (error instanceof ServerError) {
|
|
52
55
|
set.status = error.getStatusCode();
|
|
53
|
-
|
|
54
|
-
error: error.message,
|
|
55
|
-
statusCode: error.getStatusCode()
|
|
56
|
-
};
|
|
56
|
+
throw error;
|
|
57
57
|
}
|
|
58
58
|
set.status = 500;
|
|
59
|
-
|
|
60
|
-
error: this.defaultMessageError,
|
|
61
|
-
statusCode: 500
|
|
62
|
-
};
|
|
59
|
+
throw new InternalServerError(error.message, this.defaultMessageError);
|
|
63
60
|
}
|
|
64
61
|
});
|
|
65
62
|
}
|
|
@@ -78,15 +75,11 @@ export default class HttpServer {
|
|
|
78
75
|
}
|
|
79
76
|
catch (error) {
|
|
80
77
|
if (error instanceof ServerError) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
statusCode: error.getStatusCode()
|
|
84
|
-
});
|
|
78
|
+
res.status(error.getStatusCode());
|
|
79
|
+
throw error;
|
|
85
80
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
statusCode: 500
|
|
89
|
-
});
|
|
81
|
+
res.status(500);
|
|
82
|
+
throw new InternalServerError(error.message, this.defaultMessageError);
|
|
90
83
|
}
|
|
91
84
|
});
|
|
92
85
|
}
|
|
@@ -21,3 +21,8 @@ export declare class Unauthorized extends ServerError {
|
|
|
21
21
|
export declare class BadRequest extends ServerError {
|
|
22
22
|
constructor(message: string);
|
|
23
23
|
}
|
|
24
|
+
export declare class InternalServerError extends ServerError {
|
|
25
|
+
private unexpectedError;
|
|
26
|
+
constructor(unexpectedError: string, defaultMessage?: string);
|
|
27
|
+
getUnexpectedError(): string;
|
|
28
|
+
}
|
package/dist/http/ServerError.js
CHANGED
|
@@ -39,3 +39,13 @@ export class BadRequest extends ServerError {
|
|
|
39
39
|
super(message, 400);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
export class InternalServerError extends ServerError {
|
|
43
|
+
unexpectedError;
|
|
44
|
+
constructor(unexpectedError, defaultMessage = 'Ops, An unexpected error occurred') {
|
|
45
|
+
super(defaultMessage, 500);
|
|
46
|
+
this.unexpectedError = unexpectedError;
|
|
47
|
+
}
|
|
48
|
+
getUnexpectedError() {
|
|
49
|
+
return this.unexpectedError;
|
|
50
|
+
}
|
|
51
|
+
}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import HttpServer from "./HttpServer";
|
|
2
|
-
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest } from "./ServerError";
|
|
3
|
-
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer };
|
|
2
|
+
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError } from "./ServerError";
|
|
3
|
+
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer, InternalServerError };
|
package/dist/http/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import HttpServer from "./HttpServer";
|
|
2
|
-
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest } from "./ServerError";
|
|
3
|
-
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer };
|
|
2
|
+
import { ServerError, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, BadRequest, InternalServerError } from "./ServerError";
|
|
3
|
+
export { ServerError, BadRequest, NotFound, Forbidden, Conflict, Unauthorized, UnprocessableEntity, HttpServer, InternalServerError };
|