@athenna/http 1.1.7 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "1.1.7",
3
+ "version": "1.2.0",
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.7",
161
+ "@athenna/config": "1.0.8",
162
162
  "@athenna/ioc": "1.1.2",
163
- "@athenna/logger": "1.1.3",
163
+ "@athenna/logger": "1.1.4",
164
164
  "@secjs/utils": "1.8.3",
165
165
  "fastify": "3.27.4",
166
166
  "reflect-metadata": "0.1.13",
@@ -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, request, response }: ErrorContextContract): void | Promise<void>;
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, request, response }) {
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 isNotDebugMode = !config_1.Config.get('app.debug');
33
- if (isInternalServerError && isNotDebugMode) {
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
- new logger_1.Logger().error(`Error: ${JSON.stringify(body.error, null, 2)}`, {
40
- context: HttpErrorHandler.name,
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
  }
@@ -19,7 +19,7 @@ class HttpKernel {
19
19
  if (config_1.Config.get('http.log')) {
20
20
  httpServer.use(async (ctx) => {
21
21
  await new logger_1.Logger().channel('request').log(ctx);
22
- return ctx.body;
22
+ return ctx.next();
23
23
  }, 'terminate');
24
24
  }
25
25
  }