@athenna/http 1.1.9 → 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.9",
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>",
@@ -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
  }