@athenna/http 1.2.1 → 1.2.4
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 +3 -3
- package/src/Facades/Route.js +2 -2
- package/src/Facades/Server.js +2 -2
- package/src/Handlers/HttpErrorHandler.js +12 -14
- package/src/Kernels/HttpKernel.js +2 -2
- package/src/Utils/Handler.d.ts +0 -13
- package/src/Utils/Handler.js +0 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "The Athenna Http server. Built on top of fastify",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -159,8 +159,8 @@
|
|
|
159
159
|
},
|
|
160
160
|
"dependencies": {
|
|
161
161
|
"@athenna/config": "1.0.8",
|
|
162
|
-
"@athenna/ioc": "1.1.
|
|
163
|
-
"@athenna/logger": "1.1.
|
|
162
|
+
"@athenna/ioc": "1.1.3",
|
|
163
|
+
"@athenna/logger": "1.1.7",
|
|
164
164
|
"@secjs/utils": "1.8.3",
|
|
165
165
|
"fastify": "3.27.4",
|
|
166
166
|
"reflect-metadata": "0.1.13",
|
package/src/Facades/Route.js
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.Route = void 0;
|
|
12
|
-
const
|
|
13
|
-
exports.Route =
|
|
12
|
+
const ioc_1 = require("@athenna/ioc");
|
|
13
|
+
exports.Route = ioc_1.Facade.createFor('Athenna/Core/HttpRoute');
|
package/src/Facades/Server.js
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.Server = void 0;
|
|
12
|
-
const
|
|
13
|
-
exports.Server =
|
|
12
|
+
const ioc_1 = require("@athenna/ioc");
|
|
13
|
+
exports.Server = ioc_1.Facade.createFor('Athenna/Core/HttpServer');
|
|
@@ -17,26 +17,24 @@ class HttpErrorHandler {
|
|
|
17
17
|
const code = error.code || error.name;
|
|
18
18
|
const statusCode = error.statusCode || error.status || 500;
|
|
19
19
|
const body = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
stack: error.stack,
|
|
26
|
-
},
|
|
20
|
+
statusCode,
|
|
21
|
+
code: utils_1.String.toSnakeCase(`${code}`).toUpperCase(),
|
|
22
|
+
name: error.name,
|
|
23
|
+
message: error.message,
|
|
24
|
+
stack: error.stack,
|
|
27
25
|
};
|
|
28
26
|
if (error.help) {
|
|
29
|
-
body.
|
|
27
|
+
body.help = error.help;
|
|
30
28
|
}
|
|
31
29
|
const isInternalServerError = statusCode === 500;
|
|
32
|
-
const isDebugMode =
|
|
30
|
+
const isDebugMode = config_1.Config.get('app.debug');
|
|
33
31
|
if (isInternalServerError && !isDebugMode) {
|
|
34
|
-
body.
|
|
35
|
-
body.
|
|
36
|
-
delete body.
|
|
32
|
+
body.name = 'Internal server error';
|
|
33
|
+
body.message = 'An internal server exception has occurred.';
|
|
34
|
+
delete body.stack;
|
|
37
35
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
36
|
+
if (isDebugMode) {
|
|
37
|
+
logger_1.Log.error(`Error: ${JSON.stringify(body, null, 2)}`, {
|
|
40
38
|
formatterConfig: {
|
|
41
39
|
context: HttpErrorHandler.name,
|
|
42
40
|
},
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpKernel = void 0;
|
|
4
|
-
const config_1 = require("@athenna/config");
|
|
5
4
|
const logger_1 = require("@athenna/logger");
|
|
5
|
+
const config_1 = require("@athenna/config");
|
|
6
6
|
const utils_1 = require("@secjs/utils");
|
|
7
7
|
const HttpErrorHandler_1 = require("../Handlers/HttpErrorHandler");
|
|
8
8
|
class HttpKernel {
|
|
@@ -18,7 +18,7 @@ class HttpKernel {
|
|
|
18
18
|
httpServer.setErrorHandler(HttpErrorHandler_1.HttpErrorHandler.handler);
|
|
19
19
|
if (config_1.Config.get('http.log')) {
|
|
20
20
|
httpServer.use(async (ctx) => {
|
|
21
|
-
await
|
|
21
|
+
await logger_1.Log.channel('request').log(ctx);
|
|
22
22
|
return ctx.next();
|
|
23
23
|
}, 'terminate');
|
|
24
24
|
}
|
package/src/Utils/Handler.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/http
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
export declare class Handler {
|
|
10
|
-
private readonly alias;
|
|
11
|
-
constructor(alias: any);
|
|
12
|
-
get(_object: any, key: string): any;
|
|
13
|
-
}
|
package/src/Utils/Handler.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @athenna/http
|
|
4
|
-
*
|
|
5
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.Handler = void 0;
|
|
12
|
-
class Handler {
|
|
13
|
-
constructor(alias) {
|
|
14
|
-
this.alias = alias;
|
|
15
|
-
}
|
|
16
|
-
get(_object, key) {
|
|
17
|
-
const provider = ioc.use(this.alias);
|
|
18
|
-
if (!provider) {
|
|
19
|
-
return () => { };
|
|
20
|
-
}
|
|
21
|
-
return provider[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.Handler = Handler;
|