@athenna/http 1.1.8 → 1.2.1
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/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +3 -3
- package/src/Facades/Route.d.ts +10 -0
- package/src/Facades/Route.js +13 -0
- package/src/Facades/Server.d.ts +10 -0
- package/src/Facades/Server.js +13 -0
- package/src/Handlers/HttpErrorHandler.d.ts +1 -1
- package/src/Handlers/HttpErrorHandler.js +16 -13
- package/src/Utils/Handler.d.ts +13 -0
- package/src/Utils/Handler.js +24 -0
package/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
+
export * from './src/Facades/Route';
|
|
10
|
+
export * from './src/Facades/Server';
|
|
9
11
|
export * from './src/Http';
|
|
10
12
|
export * from './src/Router/Router';
|
|
11
13
|
export * from './src/Kernels/HttpKernel';
|
package/index.js
CHANGED
|
@@ -18,6 +18,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./src/Facades/Route"), exports);
|
|
22
|
+
__exportStar(require("./src/Facades/Server"), exports);
|
|
21
23
|
__exportStar(require("./src/Http"), exports);
|
|
22
24
|
__exportStar(require("./src/Router/Router"), exports);
|
|
23
25
|
__exportStar(require("./src/Kernels/HttpKernel"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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>",
|
|
@@ -158,9 +158,9 @@
|
|
|
158
158
|
}
|
|
159
159
|
},
|
|
160
160
|
"dependencies": {
|
|
161
|
-
"@athenna/config": "1.0.
|
|
161
|
+
"@athenna/config": "1.0.8",
|
|
162
162
|
"@athenna/ioc": "1.1.2",
|
|
163
|
-
"@athenna/logger": "1.1.
|
|
163
|
+
"@athenna/logger": "1.1.6",
|
|
164
164
|
"@secjs/utils": "1.8.3",
|
|
165
165
|
"fastify": "3.27.4",
|
|
166
166
|
"reflect-metadata": "0.1.13",
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import { Router } from '../Router/Router';
|
|
10
|
+
export declare const Route: Router;
|
|
@@ -0,0 +1,13 @@
|
|
|
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.Route = void 0;
|
|
12
|
+
const Handler_1 = require("../Utils/Handler");
|
|
13
|
+
exports.Route = new Proxy({}, new Handler_1.Handler('Athenna/Core/HttpRoute'));
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import { Http } from '../Http';
|
|
10
|
+
export declare const Server: Http;
|
|
@@ -0,0 +1,13 @@
|
|
|
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.Server = void 0;
|
|
12
|
+
const Handler_1 = require("../Utils/Handler");
|
|
13
|
+
exports.Server = new Proxy({}, new Handler_1.Handler('Athenna/Core/HttpServer'));
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { ErrorContextContract } from '../Contracts/Context/Error/ErrorContextContract';
|
|
10
10
|
export declare class HttpErrorHandler {
|
|
11
|
-
static handler({ error,
|
|
11
|
+
static handler({ error, response }: ErrorContextContract): void | Promise<void>;
|
|
12
12
|
}
|
|
@@ -13,32 +13,35 @@ const utils_1 = require("@secjs/utils");
|
|
|
13
13
|
const logger_1 = require("@athenna/logger");
|
|
14
14
|
const config_1 = require("@athenna/config");
|
|
15
15
|
class HttpErrorHandler {
|
|
16
|
-
static handler({ error,
|
|
16
|
+
static handler({ error, response }) {
|
|
17
17
|
const code = error.code || error.name;
|
|
18
18
|
const statusCode = error.statusCode || error.status || 500;
|
|
19
19
|
const body = {
|
|
20
|
-
code: utils_1.String.toSnakeCase(code).toUpperCase(),
|
|
21
|
-
path: request.baseUrl,
|
|
22
|
-
method: request.method,
|
|
23
|
-
status: statusCode <= 399 ? 'SUCCESS' : 'ERROR',
|
|
24
|
-
statusCode: statusCode,
|
|
25
20
|
error: {
|
|
21
|
+
statusCode,
|
|
22
|
+
code: utils_1.String.toSnakeCase(code).toUpperCase(),
|
|
26
23
|
name: error.name,
|
|
27
24
|
message: error.message,
|
|
28
25
|
stack: error.stack,
|
|
29
26
|
},
|
|
30
27
|
};
|
|
28
|
+
if (error.help) {
|
|
29
|
+
body.error.help = error.help;
|
|
30
|
+
}
|
|
31
31
|
const isInternalServerError = statusCode === 500;
|
|
32
|
-
const
|
|
33
|
-
if (isInternalServerError &&
|
|
32
|
+
const isDebugMode = !config_1.Config.get('app.debug');
|
|
33
|
+
if (isInternalServerError && !isDebugMode) {
|
|
34
34
|
body.error.name = 'Internal server error';
|
|
35
|
-
body.error.message =
|
|
36
|
-
'An internal server exception has occurred. Please contact administration of this service.';
|
|
35
|
+
body.error.message = 'An internal server exception has occurred.';
|
|
37
36
|
delete body.error.stack;
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (!isDebugMode) {
|
|
39
|
+
new logger_1.Logger().error(`Error: ${JSON.stringify(body.error, null, 2)}`, {
|
|
40
|
+
formatterConfig: {
|
|
41
|
+
context: HttpErrorHandler.name,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
42
45
|
return response.status(statusCode).send(body);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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;
|