@athenna/http 1.3.3 → 1.3.6

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.
Files changed (95) hide show
  1. package/LICENSE.md +3 -15
  2. package/README.md +8 -5
  3. package/package.json +95 -106
  4. package/src/Context/Request.js +168 -137
  5. package/src/Context/Response.js +102 -94
  6. package/src/Exceptions/UndefinedMethodException.js +30 -0
  7. package/src/Facades/Route.js +7 -5
  8. package/src/Facades/Server.js +7 -5
  9. package/src/Handlers/FastifyHandler.js +134 -115
  10. package/src/Handlers/HttpExceptionHandler.js +72 -68
  11. package/src/Kernels/HttpKernel.js +142 -124
  12. package/src/Providers/ControllerProvider.js +30 -39
  13. package/src/Providers/HttpRouteProvider.js +15 -16
  14. package/src/Providers/HttpServerProvider.js +13 -15
  15. package/src/Providers/MiddlewareProvider.js +30 -39
  16. package/src/Router/Route.js +192 -99
  17. package/src/Router/RouteGroup.js +66 -40
  18. package/src/Router/RouteResource.js +156 -74
  19. package/src/Router/Router.js +284 -112
  20. package/src/Utils/isMiddlewareContract.js +8 -6
  21. package/src/Utils/removeSlashes.js +21 -0
  22. package/src/index.d.ts +658 -0
  23. package/src/index.js +284 -0
  24. package/index.d.ts +0 -29
  25. package/index.js +0 -41
  26. package/src/Context/Request.d.ts +0 -103
  27. package/src/Context/Response.d.ts +0 -77
  28. package/src/Contracts/Context/ContextContract.d.ts +0 -17
  29. package/src/Contracts/Context/ContextContract.js +0 -10
  30. package/src/Contracts/Context/Error/ErrorContextContract.d.ts +0 -18
  31. package/src/Contracts/Context/Error/ErrorContextContract.js +0 -10
  32. package/src/Contracts/Context/Error/ErrorHandlerContract.d.ts +0 -12
  33. package/src/Contracts/Context/Error/ErrorHandlerContract.js +0 -10
  34. package/src/Contracts/Context/HandlerContract.d.ts +0 -12
  35. package/src/Contracts/Context/HandlerContract.js +0 -10
  36. package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.d.ts +0 -19
  37. package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.js +0 -10
  38. package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.d.ts +0 -12
  39. package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.js +0 -10
  40. package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.d.ts +0 -19
  41. package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.js +0 -10
  42. package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.d.ts +0 -12
  43. package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.js +0 -10
  44. package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.d.ts +0 -23
  45. package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.js +0 -10
  46. package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.d.ts +0 -12
  47. package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.js +0 -10
  48. package/src/Contracts/Context/NextContract.d.ts +0 -11
  49. package/src/Contracts/Context/NextContract.js +0 -10
  50. package/src/Contracts/Context/RequestContract.d.ts +0 -25
  51. package/src/Contracts/Context/RequestContract.js +0 -10
  52. package/src/Contracts/Context/ResponseContract.d.ts +0 -20
  53. package/src/Contracts/Context/ResponseContract.js +0 -2
  54. package/src/Contracts/FastifyErrorHandlerContract.d.ts +0 -12
  55. package/src/Contracts/FastifyErrorHandlerContract.js +0 -10
  56. package/src/Contracts/FastifyHandlerContract.d.ts +0 -12
  57. package/src/Contracts/FastifyHandlerContract.js +0 -10
  58. package/src/Contracts/HttpMethodTypes.d.ts +0 -9
  59. package/src/Contracts/HttpMethodTypes.js +0 -10
  60. package/src/Contracts/MiddlewareContract.d.ts +0 -16
  61. package/src/Contracts/MiddlewareContract.js +0 -10
  62. package/src/Contracts/MiddlewareTypes.d.ts +0 -9
  63. package/src/Contracts/MiddlewareTypes.js +0 -10
  64. package/src/Contracts/MiddlewareTypesContract.d.ts +0 -16
  65. package/src/Contracts/MiddlewareTypesContract.js +0 -10
  66. package/src/Contracts/RouteContract.d.ts +0 -16
  67. package/src/Contracts/RouteContract.js +0 -10
  68. package/src/Exceptions/BadRequestException.d.ts +0 -12
  69. package/src/Exceptions/BadRequestException.js +0 -18
  70. package/src/Exceptions/CannotDefineGroupException.d.ts +0 -12
  71. package/src/Exceptions/CannotDefineGroupException.js +0 -19
  72. package/src/Exceptions/MiddlewareNotFoundException.d.ts +0 -12
  73. package/src/Exceptions/MiddlewareNotFoundException.js +0 -19
  74. package/src/Exceptions/UndefinedControllerMethodException.d.ts +0 -12
  75. package/src/Exceptions/UndefinedControllerMethodException.js +0 -19
  76. package/src/Facades/Route.d.ts +0 -10
  77. package/src/Facades/Server.d.ts +0 -10
  78. package/src/Handlers/FastifyHandler.d.ts +0 -26
  79. package/src/Handlers/HttpExceptionHandler.d.ts +0 -27
  80. package/src/Http.d.ts +0 -167
  81. package/src/Http.js +0 -223
  82. package/src/Kernels/HttpKernel.d.ts +0 -54
  83. package/src/Providers/ControllerProvider.d.ts +0 -17
  84. package/src/Providers/HttpRouteProvider.d.ts +0 -17
  85. package/src/Providers/HttpServerProvider.d.ts +0 -17
  86. package/src/Providers/MiddlewareProvider.d.ts +0 -17
  87. package/src/Router/Route.d.ts +0 -32
  88. package/src/Router/RouteGroup.d.ts +0 -24
  89. package/src/Router/RouteResource.d.ts +0 -29
  90. package/src/Router/Router.d.ts +0 -39
  91. package/src/Utils/getAppFiles.d.ts +0 -10
  92. package/src/Utils/getAppFiles.js +0 -22
  93. package/src/Utils/isMiddlewareContract.d.ts +0 -10
  94. package/src/Utils/removeSlash.d.ts +0 -9
  95. package/src/Utils/removeSlash.js +0 -23
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/http
4
3
  *
@@ -7,99 +6,108 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Response = void 0;
12
- class Response {
13
- /**
14
- * Create a new instance of Response.
15
- *
16
- * @return Response
17
- */
18
- constructor(response) {
19
- this.response = response;
9
+
10
+ export class Response {
11
+ /**
12
+ * Fastify response object.
13
+ *
14
+ * @type {import('fastify').FastifyReply}
15
+ */
16
+ #response
17
+
18
+ /**
19
+ * Create a new instance of Response.
20
+ *
21
+ * @param {import('fastify').FastifyReply} response
22
+ * @return {Response}
23
+ */
24
+ constructor(response) {
25
+ this.#response = response
26
+ }
27
+
28
+ /**
29
+ * Terminate the request sending the response body.
30
+ *
31
+ * @param {any} [data]
32
+ * @return {void}
33
+ */
34
+ send(data) {
35
+ this.#response.send(data)
36
+ }
37
+
38
+ /**
39
+ * Set the response status code.
40
+ *
41
+ * @param {number} code
42
+ * @return {Response}
43
+ */
44
+ status(code) {
45
+ this.#response.status(code)
46
+
47
+ return this
48
+ }
49
+
50
+ /**
51
+ * Remove some header from the response.
52
+ *
53
+ * @param {string} header
54
+ * @return {Response}
55
+ */
56
+ removeHeader(header) {
57
+ this.#response.removeHeader(header)
58
+
59
+ return this
60
+ }
61
+
62
+ /**
63
+ * Add some header to the response.
64
+ *
65
+ * @param {string} header
66
+ * @param {any} value
67
+ * @return {Response}
68
+ */
69
+ header(header, value) {
70
+ this.#response.header(header, value)
71
+
72
+ return this
73
+ }
74
+
75
+ /**
76
+ * Only add some header to the response if it's not defined yet.
77
+ *
78
+ * @param {string} header
79
+ * @param {any} value
80
+ * @return {Response}
81
+ */
82
+ safeHeader(header, value) {
83
+ if (!this.#response.hasHeader(header)) {
84
+ this.#response.header(header, value)
20
85
  }
21
- /**
22
- * Terminate the request sending the response body.
23
- *
24
- * @param data
25
- * @return void
26
- */
27
- send(data) {
28
- this.response.send(data);
29
- }
30
- /**
31
- * Terminate the request sending the response body.
32
- *
33
- * @param data
34
- * @return void
35
- */
36
- json(data) {
37
- this.response.send(this.response.serialize(data));
38
- }
39
- /**
40
- * Set the response status code.
41
- *
42
- * @param code
43
- * @return Response
44
- */
45
- status(code) {
46
- this.response.status(code);
47
- return this;
48
- }
49
- /**
50
- * Remove some header from the response.
51
- *
52
- * @param header
53
- * @return Response
54
- */
55
- removeHeader(header) {
56
- this.response.removeHeader(header);
57
- return this;
58
- }
59
- /**
60
- * Add some header to the response.
61
- *
62
- * @param header
63
- * @param value
64
- * @return Response
65
- */
66
- header(header, value) {
67
- this.response.header(header, value);
68
- return this;
69
- }
70
- /**
71
- * Only add some header to the response if it's not defined yet.
72
- *
73
- * @param header
74
- * @param value
75
- * @return Response
76
- */
77
- safeHeader(header, value) {
78
- if (!this.response.hasHeader(header)) {
79
- this.response.header(header, value);
80
- }
81
- return this;
82
- }
83
- /**
84
- * Redirect the response to other url with different status code.
85
- *
86
- * @param url
87
- * @param statusCode
88
- * @return void
89
- */
90
- redirectTo(url, statusCode) {
91
- if (statusCode) {
92
- this.response.redirect(statusCode, url);
93
- }
94
- this.response.redirect(url);
95
- }
96
- /**
97
- * Get the default fastify response object.
98
- *
99
- * @return FastifyReply
100
- */
101
- getFastifyResponse() {
102
- return this.response;
86
+
87
+ return this
88
+ }
89
+
90
+ /**
91
+ * Redirect the response to other url with different status code.
92
+ *
93
+ * @param {string} url
94
+ * @param {number} [statusCode]
95
+ * @return {void}
96
+ */
97
+ redirectTo(url, statusCode) {
98
+ if (statusCode) {
99
+ this.#response.redirect(statusCode, url)
103
100
  }
101
+
102
+ this.#response.redirect(url)
103
+ }
104
+
105
+ /**
106
+ * Get the default fastify response object.
107
+ *
108
+ * @return {import('fastify').FastifyReply}
109
+ */
110
+ getFastifyResponse() {
111
+ return this.#response
112
+ }
104
113
  }
105
- exports.Response = Response;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @athenna/logger
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
+
10
+ import { Exception } from '@secjs/utils'
11
+
12
+ export class UndefinedMethodException extends Exception {
13
+ /**
14
+ * Creates a new instance of UndefinedMethodException.
15
+ *
16
+ * @param {string} method
17
+ * @param {string} className
18
+ * @return {UndefinedMethodException}
19
+ */
20
+ constructor(method, className) {
21
+ const content = `The method ${method} is not defined inside your class ${className}.`
22
+
23
+ super(
24
+ content,
25
+ 500,
26
+ 'E_UNDEFINED_METHOD',
27
+ `Remember defining the method ${method} inside your class ${className}`,
28
+ )
29
+ }
30
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/http
4
3
  *
@@ -7,7 +6,10 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Route = void 0;
12
- const ioc_1 = require("@athenna/ioc");
13
- exports.Route = ioc_1.Facade.createFor('Athenna/Core/HttpRoute');
9
+
10
+ import { Facade } from '@athenna/ioc'
11
+
12
+ /**
13
+ * @type {Facade & import('../Router/Router.js').Router}
14
+ */
15
+ export const Route = Facade.createFor('Athenna/Core/HttpRoute')
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/http
4
3
  *
@@ -7,7 +6,10 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Server = void 0;
12
- const ioc_1 = require("@athenna/ioc");
13
- exports.Server = ioc_1.Facade.createFor('Athenna/Core/HttpServer');
9
+
10
+ import { Facade } from '@athenna/ioc'
11
+
12
+ /**
13
+ * @type {Facade & import('../index.js').Http}
14
+ */
15
+ export const Server = Facade.createFor('Athenna/Core/HttpServer')
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/http
4
3
  *
@@ -7,123 +6,143 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.FastifyHandler = void 0;
12
- /* eslint-disable @typescript-eslint/no-empty-function */
13
- const utils_1 = require("@secjs/utils");
14
- const Request_1 = require("../Context/Request");
15
- const Response_1 = require("../Context/Response");
16
- class FastifyHandler {
17
- static createOnSendHandler(handler) {
18
- return async (req, res, payload) => {
19
- const request = new Request_1.Request(req);
20
- const response = new Response_1.Response(res);
21
- if (!req.data)
22
- req.data = {};
23
- if (!req.query)
24
- req.query = {};
25
- if (!req.params)
26
- req.params = {};
27
- let body = payload;
28
- if (utils_1.Is.Json(payload)) {
29
- body = JSON.parse(body);
30
- }
31
- body = await handler({
32
- request,
33
- response,
34
- body,
35
- status: res.statusCode,
36
- params: req.params,
37
- queries: req.query,
38
- data: req.data,
39
- });
40
- if (utils_1.Is.Object(body))
41
- body = JSON.stringify(body);
42
- return body;
43
- };
9
+
10
+ import { Is } from '@secjs/utils'
11
+ import { Request } from '#src/Context/Request'
12
+ import { Response } from '#src/Context/Response'
13
+
14
+ export class FastifyHandler {
15
+ /**
16
+ * Creates a new onSend fastify hook.
17
+ *
18
+ * @param {any} handler
19
+ * @return {any}
20
+ */
21
+ static createOnSendHandler(handler) {
22
+ return async (req, res, payload) => {
23
+ const request = new Request(req)
24
+ const response = new Response(res)
25
+
26
+ if (!req.data) req.data = {}
27
+
28
+ let body = payload
29
+
30
+ if (Is.Json(payload)) {
31
+ body = JSON.parse(body)
32
+ }
33
+
34
+ body = await handler({
35
+ request,
36
+ response,
37
+ body,
38
+ status: res.statusCode,
39
+ params: req.params,
40
+ queries: req.query,
41
+ data: req.data,
42
+ })
43
+
44
+ if (Is.Object(body)) body = JSON.stringify(body)
45
+
46
+ return body
44
47
  }
45
- static createDoneHandler(handler) {
46
- return (req, res, done) => {
47
- const request = new Request_1.Request(req);
48
- const response = new Response_1.Response(res);
49
- if (!req.data)
50
- req.data = {};
51
- if (!req.query)
52
- req.query = {};
53
- if (!req.params)
54
- req.params = {};
55
- return handler({
56
- request,
57
- response,
58
- params: req.params,
59
- queries: req.query,
60
- data: req.data,
61
- next: done,
62
- });
63
- };
48
+ }
49
+
50
+ /**
51
+ * Creates a new done fastify hook.
52
+ *
53
+ * @param {any} handler
54
+ * @return {any}
55
+ */
56
+ static createDoneHandler(handler) {
57
+ return (req, res, done) => {
58
+ const request = new Request(req)
59
+ const response = new Response(res)
60
+
61
+ if (!req.data) req.data = {}
62
+
63
+ return handler({
64
+ request,
65
+ response,
66
+ params: req.params,
67
+ queries: req.query,
68
+ data: req.data,
69
+ next: done,
70
+ })
64
71
  }
65
- static createResponseHandler(handler) {
66
- return (req, res, done) => {
67
- const request = new Request_1.Request(req);
68
- const response = new Response_1.Response(res);
69
- if (!req.data)
70
- req.data = {};
71
- if (!req.query)
72
- req.query = {};
73
- if (!req.params)
74
- req.params = {};
75
- return handler({
76
- request,
77
- response,
78
- params: req.params,
79
- queries: req.query,
80
- data: req.data,
81
- body: req.body,
82
- headers: res.getHeaders(),
83
- status: res.statusCode,
84
- responseTime: res.getResponseTime(),
85
- next: done,
86
- });
87
- };
72
+ }
73
+
74
+ /**
75
+ * Creates a new onResponse fastify hook.
76
+ *
77
+ * @param {any} handler
78
+ * @return {any}
79
+ */
80
+ static createOnResponseHandler(handler) {
81
+ return (req, res, done) => {
82
+ const request = new Request(req)
83
+ const response = new Response(res)
84
+
85
+ if (!req.data) req.data = {}
86
+
87
+ return handler({
88
+ request,
89
+ response,
90
+ params: req.params,
91
+ queries: req.query,
92
+ data: req.data,
93
+ body: req.body,
94
+ headers: res.getHeaders(),
95
+ status: res.statusCode,
96
+ responseTime: res.getResponseTime(),
97
+ next: done,
98
+ })
88
99
  }
89
- static createErrorHandler(handler) {
90
- return (error, req, res) => {
91
- const request = new Request_1.Request(req);
92
- const response = new Response_1.Response(res);
93
- if (!req.data)
94
- req.data = {};
95
- if (!req.query)
96
- req.query = {};
97
- if (!req.params)
98
- req.params = {};
99
- return handler({
100
- request,
101
- response,
102
- params: req.params,
103
- queries: req.query,
104
- data: req.data,
105
- error,
106
- });
107
- };
100
+ }
101
+
102
+ /**
103
+ * Creates a new error fastify hook.
104
+ *
105
+ * @param {any} handler
106
+ * @return {any}
107
+ */
108
+ static createErrorHandler(handler) {
109
+ return (error, req, res) => {
110
+ const request = new Request(req)
111
+ const response = new Response(res)
112
+
113
+ if (!req.data) req.data = {}
114
+
115
+ return handler({
116
+ request,
117
+ response,
118
+ params: req.params,
119
+ queries: req.query,
120
+ data: req.data,
121
+ error,
122
+ })
108
123
  }
109
- static createRequestHandler(handler) {
110
- return async (req, res) => {
111
- const request = new Request_1.Request(req);
112
- const response = new Response_1.Response(res);
113
- if (!req.data)
114
- req.data = {};
115
- if (!req.query)
116
- req.query = {};
117
- if (!req.params)
118
- req.params = {};
119
- return handler({
120
- request,
121
- response,
122
- params: req.params,
123
- queries: req.query,
124
- data: req.data,
125
- });
126
- };
124
+ }
125
+
126
+ /**
127
+ * Creates a new request fastify hook.
128
+ *
129
+ * @param {any} handler
130
+ * @return {any}
131
+ */
132
+ static createRequestHandler(handler) {
133
+ return async (req, res) => {
134
+ const request = new Request(req)
135
+ const response = new Response(res)
136
+
137
+ if (!req.data) req.data = {}
138
+
139
+ return handler({
140
+ request,
141
+ response,
142
+ params: req.params,
143
+ queries: req.query,
144
+ data: req.data,
145
+ })
127
146
  }
147
+ }
128
148
  }
129
- exports.FastifyHandler = FastifyHandler;
@@ -1,71 +1,75 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpExceptionHandler = void 0;
4
- const logger_1 = require("@athenna/logger");
5
- const utils_1 = require("@secjs/utils");
6
- const config_1 = require("@athenna/config");
7
- class HttpExceptionHandler {
8
- constructor() {
9
- /**
10
- * Set if error logs will come with stack.
11
- *
12
- * @protected
13
- */
14
- this.addStack = false;
15
- /**
16
- * Error codes that should be ignored by Log.
17
- *
18
- * @protected
19
- */
20
- this.ignoreCodes = [];
21
- /**
22
- * Error statuses that should be ignored by Log.
23
- *
24
- * @protected
25
- */
26
- this.ignoreStatuses = [];
1
+ import { Log } from '@athenna/logger'
2
+ import { Config, Exception, String } from '@secjs/utils'
3
+
4
+ export class HttpExceptionHandler {
5
+ /**
6
+ * Error codes that should be ignored by Log.
7
+ *
8
+ * @type {string[]}
9
+ */
10
+ ignoreCodes = []
11
+
12
+ /**
13
+ * Error statuses that should be ignored by Log.
14
+ *
15
+ * @type {number[]}
16
+ */
17
+ ignoreStatuses = []
18
+
19
+ /**
20
+ * The global exception handler of all HTTP requests.
21
+ *
22
+ * @param {import('#src/index').ErrorContextContract} ctx
23
+ */
24
+ async handle({ error, response }) {
25
+ const code = error.code || error.name
26
+ const statusCode = error.statusCode || error.status || 500
27
+
28
+ const body = {
29
+ statusCode,
30
+ code: String.toSnakeCase(`${code}`).toUpperCase(),
31
+ name: error.name,
32
+ message: error.message,
33
+ stack: error.stack,
27
34
  }
28
- /**
29
- * The global exception handler of all HTTP requests.
30
- *
31
- * @param ctx
32
- */
33
- async handle({ error, response }) {
34
- const code = error.code || error.name;
35
- const statusCode = error.statusCode || error.status || 500;
36
- const body = {
37
- statusCode,
38
- code: utils_1.String.toSnakeCase(`${code}`).toUpperCase(),
39
- name: error.name,
40
- message: error.message,
41
- stack: error.stack,
42
- };
43
- if (error.help) {
44
- body.help = error.help;
45
- }
46
- const isInternalServerError = statusCode === 500;
47
- const isDebugMode = config_1.Config.get('app.debug');
48
- if (isInternalServerError && !isDebugMode) {
49
- body.name = 'Internal server error';
50
- body.message = 'An internal server exception has occurred.';
51
- delete body.stack;
52
- }
53
- if (this.ignoreCodes.includes(code) ||
54
- this.ignoreStatuses.includes(statusCode)) {
55
- return response.status(statusCode).send(body);
56
- }
57
- const logConfig = {
58
- formatterConfig: {
59
- context: 'ExceptionHandler',
60
- },
61
- };
62
- if (this.addStack) {
63
- logger_1.Log.error(`(${body.statusCode}) ${body.code}: ${body.message}\nStack: ${body.stack}`, logConfig);
64
- }
65
- else {
66
- logger_1.Log.error(`(${body.statusCode}) ${body.code}: ${body.message}`, logConfig);
67
- }
68
- return response.status(statusCode).send(body);
35
+
36
+ if (error.help) {
37
+ body.help = error.help
69
38
  }
39
+
40
+ const isInternalServerError = statusCode === 500
41
+ const isDebugMode = Config.get('app.debug')
42
+
43
+ if (isInternalServerError && !isDebugMode) {
44
+ body.name = 'Internal server error'
45
+ body.message = 'An internal server exception has occurred.'
46
+
47
+ delete body.stack
48
+ }
49
+
50
+ if (
51
+ this.ignoreCodes.includes(code) ||
52
+ this.ignoreStatuses.includes(statusCode)
53
+ ) {
54
+ return response.status(statusCode).send(body)
55
+ }
56
+
57
+ response.status(statusCode).send(body)
58
+
59
+ if (error.prettify) {
60
+ const prettyError = await error.prettify()
61
+
62
+ Log.channel('exception').error(prettyError.concat('\n'))
63
+
64
+ return
65
+ }
66
+
67
+ const prettyError = await new Exception(
68
+ body.message,
69
+ body.statusCode,
70
+ body.code,
71
+ ).prettify()
72
+
73
+ Log.channel('exception').error(prettyError.concat('\n'))
74
+ }
70
75
  }
71
- exports.HttpExceptionHandler = HttpExceptionHandler;