@athenna/http 3.0.11 → 3.1.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.
Files changed (151) hide show
  1. package/build/Commands/MakeControllerCommand.d.ts +15 -0
  2. package/build/Commands/MakeControllerCommand.js +42 -0
  3. package/build/Commands/MakeInterceptorCommand.d.ts +15 -0
  4. package/build/Commands/MakeInterceptorCommand.js +42 -0
  5. package/build/Commands/MakeMiddlewareCommand.d.ts +15 -0
  6. package/build/Commands/MakeMiddlewareCommand.js +42 -0
  7. package/build/Commands/MakeTerminatorCommand.d.ts +15 -0
  8. package/build/Commands/MakeTerminatorCommand.js +42 -0
  9. package/build/Commands/RouteListCommand.d.ts +19 -0
  10. package/build/Commands/RouteListCommand.js +62 -0
  11. package/build/Context/Request.d.ts +144 -0
  12. package/build/Context/Request.js +219 -0
  13. package/build/Context/Response.d.ts +67 -0
  14. package/build/Context/Response.js +102 -0
  15. package/build/Contracts/InterceptorContract.d.ts +15 -0
  16. package/build/Contracts/InterceptorContract.js +9 -0
  17. package/build/Contracts/MiddlewareContract.d.ts +15 -0
  18. package/build/Contracts/MiddlewareContract.js +9 -0
  19. package/build/Contracts/TerminatorContract.d.ts +15 -0
  20. package/build/Contracts/TerminatorContract.js +9 -0
  21. package/build/Decorators/Controller.d.ts +14 -0
  22. package/build/Decorators/Controller.js +28 -0
  23. package/build/Decorators/Interceptor.d.ts +14 -0
  24. package/build/Decorators/Interceptor.js +37 -0
  25. package/build/Decorators/Middleware.d.ts +14 -0
  26. package/build/Decorators/Middleware.js +37 -0
  27. package/build/Decorators/Terminator.d.ts +14 -0
  28. package/build/Decorators/Terminator.js +37 -0
  29. package/build/Exceptions/BadGatewayException.d.ts +20 -0
  30. package/build/Exceptions/BadGatewayException.js +22 -0
  31. package/build/Exceptions/BadRequestException.d.ts +20 -0
  32. package/build/Exceptions/BadRequestException.js +22 -0
  33. package/build/Exceptions/ForbiddenException.d.ts +20 -0
  34. package/build/Exceptions/ForbiddenException.js +22 -0
  35. package/build/Exceptions/HttpException.d.ts +20 -0
  36. package/build/Exceptions/HttpException.js +27 -0
  37. package/build/Exceptions/InternalServerException.d.ts +20 -0
  38. package/build/Exceptions/InternalServerException.js +22 -0
  39. package/build/Exceptions/MethodNotAllowedException.d.ts +20 -0
  40. package/build/Exceptions/MethodNotAllowedException.js +22 -0
  41. package/build/Exceptions/NotAcceptableException.d.ts +20 -0
  42. package/build/Exceptions/NotAcceptableException.js +22 -0
  43. package/build/Exceptions/NotFoundException.d.ts +20 -0
  44. package/build/Exceptions/NotFoundException.js +22 -0
  45. package/build/Exceptions/NotImplementedException.d.ts +20 -0
  46. package/build/Exceptions/NotImplementedException.js +22 -0
  47. package/build/Exceptions/PayloadTooLargeException.d.ts +20 -0
  48. package/build/Exceptions/PayloadTooLargeException.js +22 -0
  49. package/build/Exceptions/RequestTimeoutException.d.ts +20 -0
  50. package/build/Exceptions/RequestTimeoutException.js +22 -0
  51. package/build/Exceptions/ServiceUnavailableException.d.ts +20 -0
  52. package/build/Exceptions/ServiceUnavailableException.js +22 -0
  53. package/build/Exceptions/UnauthorizedException.d.ts +20 -0
  54. package/build/Exceptions/UnauthorizedException.js +22 -0
  55. package/build/Exceptions/UndefinedMethodException.d.ts +12 -0
  56. package/build/Exceptions/UndefinedMethodException.js +19 -0
  57. package/build/Exceptions/UnprocessableEntityException.d.ts +20 -0
  58. package/build/Exceptions/UnprocessableEntityException.js +22 -0
  59. package/build/Facades/Route.d.ts +10 -0
  60. package/{src → build}/Facades/Route.js +2 -7
  61. package/build/Facades/Server.d.ts +10 -0
  62. package/{src → build}/Facades/Server.js +2 -7
  63. package/build/Handlers/FastifyHandler.d.ts +41 -0
  64. package/build/Handlers/FastifyHandler.js +116 -0
  65. package/build/Handlers/HttpExceptionHandler.d.ts +31 -0
  66. package/build/Handlers/HttpExceptionHandler.js +82 -0
  67. package/build/Kernels/HttpKernel.d.ts +73 -0
  68. package/build/Kernels/HttpKernel.js +221 -0
  69. package/build/Providers/HttpRouteProvider.d.ts +12 -0
  70. package/build/Providers/HttpRouteProvider.js +15 -0
  71. package/build/Providers/HttpServerProvider.d.ts +13 -0
  72. package/build/Providers/HttpServerProvider.js +25 -0
  73. package/build/Router/Route.d.ts +263 -0
  74. package/build/Router/Route.js +447 -0
  75. package/build/Router/RouteGroup.d.ts +96 -0
  76. package/build/Router/RouteGroup.js +123 -0
  77. package/build/Router/RouteResource.d.ts +108 -0
  78. package/build/Router/RouteResource.js +158 -0
  79. package/build/Router/Router.d.ts +103 -0
  80. package/build/Router/Router.js +188 -0
  81. package/build/Server/ServerImpl.d.ts +129 -0
  82. package/build/Server/ServerImpl.js +213 -0
  83. package/build/Types/Contexts/Context.d.ts +20 -0
  84. package/build/Types/Contexts/Context.js +9 -0
  85. package/build/Types/Contexts/ErrorContext.d.ts +21 -0
  86. package/build/Types/Contexts/ErrorContext.js +9 -0
  87. package/build/Types/Contexts/InterceptContext.d.ts +20 -0
  88. package/build/Types/Contexts/InterceptContext.js +9 -0
  89. package/build/Types/Contexts/TerminateContext.d.ts +21 -0
  90. package/build/Types/Contexts/TerminateContext.js +9 -0
  91. package/build/Types/Controllers/ControllerOptions.d.ts +25 -0
  92. package/build/Types/Controllers/ControllerOptions.js +9 -0
  93. package/build/Types/Middlewares/InterceptorRouteType.d.ts +11 -0
  94. package/build/Types/Middlewares/InterceptorRouteType.js +9 -0
  95. package/build/Types/Middlewares/MiddlewareHandler.d.ts +20 -0
  96. package/build/Types/Middlewares/MiddlewareHandler.js +9 -0
  97. package/build/Types/Middlewares/MiddlewareOptions.d.ts +40 -0
  98. package/build/Types/Middlewares/MiddlewareOptions.js +9 -0
  99. package/build/Types/Middlewares/MiddlewareRouteType.d.ts +11 -0
  100. package/build/Types/Middlewares/MiddlewareRouteType.js +9 -0
  101. package/build/Types/Middlewares/TerminatorRouteType.d.ts +11 -0
  102. package/build/Types/Middlewares/TerminatorRouteType.js +9 -0
  103. package/build/Types/Router/RouteHandler.d.ts +10 -0
  104. package/build/Types/Router/RouteHandler.js +9 -0
  105. package/build/Types/Router/RouteJSON.d.ts +21 -0
  106. package/build/Types/Router/RouteJSON.js +9 -0
  107. package/build/Types/Router/RouteResourceTypes.d.ts +9 -0
  108. package/build/Types/Router/RouteResourceTypes.js +9 -0
  109. package/build/index.d.ts +70 -0
  110. package/build/index.js +48 -0
  111. package/package.json +159 -77
  112. package/templates/controller.edge +8 -36
  113. package/templates/interceptor.edge +8 -0
  114. package/templates/middleware.edge +4 -36
  115. package/templates/terminator.edge +6 -0
  116. package/src/Commands/Make/Controller.js +0 -64
  117. package/src/Commands/Make/Middleware.js +0 -80
  118. package/src/Commands/Route/List.js +0 -107
  119. package/src/Context/Request.js +0 -268
  120. package/src/Context/Response.js +0 -173
  121. package/src/Exceptions/BadGatewayException.js +0 -31
  122. package/src/Exceptions/BadRequestException.js +0 -31
  123. package/src/Exceptions/ForbiddenException.js +0 -31
  124. package/src/Exceptions/HttpException.js +0 -33
  125. package/src/Exceptions/InternalServerException.js +0 -31
  126. package/src/Exceptions/MethodNotAllowedException.js +0 -31
  127. package/src/Exceptions/NotAcceptableException.js +0 -31
  128. package/src/Exceptions/NotFoundException.js +0 -31
  129. package/src/Exceptions/NotImplementedException.js +0 -31
  130. package/src/Exceptions/PayloadTooLargeException.js +0 -31
  131. package/src/Exceptions/RequestTimeoutException.js +0 -31
  132. package/src/Exceptions/ServiceUnavailableException.js +0 -31
  133. package/src/Exceptions/UnauthorizedException.js +0 -31
  134. package/src/Exceptions/UndefinedMethodException.js +0 -30
  135. package/src/Exceptions/UnprocessableEntityException.js +0 -31
  136. package/src/Handlers/FastifyHandler.js +0 -148
  137. package/src/Handlers/HttpExceptionHandler.js +0 -88
  138. package/src/Helpers/HttpLoader.js +0 -38
  139. package/src/Kernels/HttpKernel.js +0 -199
  140. package/src/Providers/ControllerProvider.js +0 -29
  141. package/src/Providers/HttpRouteProvider.js +0 -24
  142. package/src/Providers/HttpServerProvider.js +0 -37
  143. package/src/Providers/MiddlewareProvider.js +0 -29
  144. package/src/Router/Route.js +0 -411
  145. package/src/Router/RouteGroup.js +0 -119
  146. package/src/Router/RouteResource.js +0 -247
  147. package/src/Router/Router.js +0 -313
  148. package/src/Utils/isMiddlewareContract.js +0 -17
  149. package/src/Utils/removeSlashes.js +0 -30
  150. package/src/index.d.ts +0 -1395
  151. package/src/index.js +0 -377
@@ -1,107 +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
-
10
- import { Command } from '@athenna/artisan'
11
- import { Module, Path, String } from '@athenna/common'
12
-
13
- import { Route } from '#src/index'
14
-
15
- export class RouteList extends Command {
16
- /**
17
- * The name and signature of the console command.
18
- *
19
- * @return {string}
20
- */
21
- get signature() {
22
- return 'route:list'
23
- }
24
-
25
- /**
26
- * The console command description.
27
- *
28
- * @return {string}
29
- */
30
- get description() {
31
- return 'List all the routes of your application.'
32
- }
33
-
34
- /**
35
- * Set additional flags in the commander instance.
36
- * This method is executed when registering your command.
37
- *
38
- * @param {import('@athenna/artisan').Commander} commander
39
- * @return {import('@athenna/artisan').Commander}
40
- */
41
- addFlags(commander) {
42
- return commander.option(
43
- '-m, --middleware',
44
- 'List the middlewares of each route.',
45
- false,
46
- )
47
- }
48
-
49
- /**
50
- * Execute the console command.
51
- *
52
- * @param {any} options
53
- * @return {Promise<void>}
54
- */
55
- async handle(options) {
56
- this.title('ROUTE LISTING\n', 'bold', 'green')
57
-
58
- const Kernel = await Module.getFrom(Path.http(`Kernel.${Path.ext()}`))
59
-
60
- const kernel = new Kernel()
61
-
62
- await kernel.registerCors()
63
- await kernel.registerTracer()
64
- await kernel.registerRateLimit()
65
- await kernel.registerMiddlewares()
66
- await kernel.registerErrorHandler()
67
- await kernel.registerLogMiddleware()
68
-
69
- const routePath = Path.routes(`http.${Path.ext()}`)
70
-
71
- await import(routePath)
72
- const routes = Route.listRoutes()
73
-
74
- const header = ['Method', 'Route', 'Handler']
75
- const rows = []
76
-
77
- if (options.middleware) header.push('Middlewares')
78
-
79
- routes.forEach(route => {
80
- const row = [route.methods.join('|'), route.url, 'Closure']
81
-
82
- if (options.middleware) {
83
- let middlewares = ''
84
-
85
- Object.keys(route.middlewares).forEach(key => {
86
- if (route.middlewares[key].length) {
87
- const number = route.middlewares[key].length
88
-
89
- if (middlewares) {
90
- middlewares = middlewares + '\n'
91
- }
92
-
93
- middlewares = middlewares + `${String.toPascalCase(key)}: ${number}`
94
- }
95
- })
96
-
97
- if (!middlewares) middlewares = 'Not found'
98
-
99
- row.push(middlewares)
100
- }
101
-
102
- rows.push(row)
103
- })
104
-
105
- this.log(this.createTable({ head: header }, ...rows))
106
- }
107
- }
@@ -1,268 +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
-
10
- import { Config } from '@athenna/config'
11
- import { Is, Json } from '@athenna/common'
12
- import { Server } from '#src/index'
13
-
14
- export class Request {
15
- /**
16
- * Fastify request object.
17
- *
18
- * @type {import('fastify').FastifyRequest}
19
- */
20
- #request
21
-
22
- /**
23
- * Create a new instance of Request.
24
- *
25
- * @param {import('fastify').FastifyRequest} request
26
- * @return {Request}
27
- */
28
- constructor(request) {
29
- this.#request = request
30
- }
31
-
32
- /**
33
- * Get the request id.
34
- *
35
- * @return {string}
36
- */
37
- get id() {
38
- return this.#request.id
39
- }
40
-
41
- /**
42
- * Get the request ip.
43
- *
44
- * @return {string}
45
- */
46
- get ip() {
47
- return this.#request.ip
48
- }
49
-
50
- /**
51
- * Get the request hostname.
52
- *
53
- * @return {string}
54
- */
55
- get hostname() {
56
- return this.#request.hostname
57
- }
58
-
59
- /**
60
- * Get the request protocol.
61
- *
62
- * @return {"http"|"https"}
63
- */
64
- get protocol() {
65
- return this.#request.protocol
66
- }
67
-
68
- /**
69
- * Get the request method.
70
- *
71
- * @return {string}
72
- */
73
- get method() {
74
- return this.#request.method
75
- }
76
-
77
- /**
78
- * Get the route url from request.
79
- *
80
- * @return {string}
81
- */
82
- get routeUrl() {
83
- return this.#request.routerPath
84
- }
85
-
86
- /**
87
- * Get the host url from request.
88
- *
89
- * @return {string}
90
- */
91
- get hostUrl() {
92
- const port = Config.get('http.port', Server.getPort())
93
- let host = Config.get('http.domain', `http://localhost:${port}`)
94
-
95
- if (!Is.Ip(host) && !host.includes('localhost')) {
96
- host = host.replace(`:${port}`, '')
97
- }
98
-
99
- return host.concat(this.originalUrl)
100
- }
101
-
102
- /**
103
- * Get the base request url.
104
- *
105
- * @return {string}
106
- */
107
- get baseUrl() {
108
- return this.#request.url.split('?')[0]
109
- }
110
-
111
- /**
112
- * Get the original request url.
113
- *
114
- * @return {string}
115
- */
116
- get originalUrl() {
117
- return this.#request.url
118
- }
119
-
120
- /**
121
- * Get all body from request.
122
- *
123
- * @return {any}
124
- */
125
- get body() {
126
- return this.#request.body || {}
127
- }
128
-
129
- /**
130
- * Get all params from request.
131
- *
132
- * @return {any}
133
- */
134
- get params() {
135
- return this.#request.params || {}
136
- }
137
-
138
- /**
139
- * Get all queries from request.
140
- *
141
- * @return {any}
142
- */
143
- get queries() {
144
- return this.#request.query || {}
145
- }
146
-
147
- /**
148
- * Get all headers from request.
149
- *
150
- * @return {any}
151
- */
152
- get headers() {
153
- return this.#request.headers || {}
154
- }
155
-
156
- /**
157
- * Get the server version.
158
- *
159
- * @return {string}
160
- */
161
- get version() {
162
- return this.#request.server.version
163
- }
164
-
165
- /**
166
- * Get a value from the request params or the default value.
167
- *
168
- * @param {string} param
169
- * @param {string} [defaultValue]
170
- * @return {any}
171
- */
172
- param(param, defaultValue) {
173
- return this.params[param] || defaultValue
174
- }
175
-
176
- /**
177
- * Get a value from the request query param or the default value.
178
- *
179
- * @param {string} query
180
- * @param {string} [defaultValue]
181
- * @return {any}
182
- */
183
- query(query, defaultValue) {
184
- return this.queries[query] || defaultValue
185
- }
186
-
187
- /**
188
- * Get a value from the request header or the default value.
189
- *
190
- * @param {string} header
191
- * @param {string} [defaultValue]
192
- * @return {any}
193
- */
194
- header(header, defaultValue) {
195
- return this.headers[header] || defaultValue
196
- }
197
-
198
- /**
199
- * Get only the selected values from the request body.
200
- *
201
- * @param {string} keys
202
- * @return {any}
203
- */
204
- only(...keys) {
205
- const body = {}
206
-
207
- Object.keys(this.body).forEach(key => {
208
- if (!keys.includes(key)) {
209
- return
210
- }
211
-
212
- body[key] = this.body[key]
213
- })
214
-
215
- return body
216
- }
217
-
218
- /**
219
- * Get all the values from the request body except the selected ones.
220
- *
221
- * @param {string[]} keys
222
- * @return {any}
223
- */
224
- except(...keys) {
225
- const body = {}
226
-
227
- Object.keys(this.body).forEach(key => {
228
- if (keys.includes(key)) {
229
- return
230
- }
231
-
232
- body[key] = this.body[key]
233
- })
234
-
235
- return body
236
- }
237
-
238
- /**
239
- * Get a value from the request body or the default value.
240
- *
241
- * @param {string} key
242
- * @param {string} [defaultValue]
243
- * @return {any}
244
- */
245
- input(key, defaultValue) {
246
- return this.payload(key, defaultValue)
247
- }
248
-
249
- /**
250
- * Get a value from the request body or the default value.
251
- *
252
- * @param {string} key
253
- * @param {string} [defaultValue]
254
- * @return {any}
255
- */
256
- payload(key, defaultValue) {
257
- return Json.get(this.body, key, defaultValue)
258
- }
259
-
260
- /**
261
- * Get the default fastify request object.
262
- *
263
- * @return {import('fastify').FastifyRequest}
264
- */
265
- getFastifyRequest() {
266
- return this.#request
267
- }
268
- }
@@ -1,173 +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
-
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
- * Verify if response has been already sent.
30
- *
31
- * @return {boolean}
32
- */
33
- get sent() {
34
- return this.#response.sent
35
- }
36
-
37
- /**
38
- * Get the status code sent in response.
39
- *
40
- * @return {number}
41
- */
42
- get statusCode() {
43
- return this.#response.statusCode
44
- }
45
-
46
- /**
47
- * Get the headers sent in response.
48
- *
49
- * @return {any}
50
- */
51
- get headers() {
52
- return this.#response.getHeaders()
53
- }
54
-
55
- /**
56
- * Get the response time.
57
- *
58
- * @return {number}
59
- */
60
- get responseTime() {
61
- return this.#response.getResponseTime()
62
- }
63
-
64
- /**
65
- * Terminate the request sending the response body.
66
- *
67
- * @param {any} [data]
68
- * @return {void}
69
- */
70
- send(data) {
71
- this.#response.send(data)
72
- }
73
-
74
- /**
75
- * Terminate the request sending the response body.
76
- *
77
- * @param {any} [data]
78
- * @return {void}
79
- */
80
- json(data) {
81
- this.#response.send(data)
82
- }
83
-
84
- /**
85
- * Apply helmet in response.
86
- *
87
- * @param {import('@fastify/helmet').FastifyHelmetOptions} [options]
88
- * @return {void}
89
- */
90
- async helmet(options) {
91
- await this.#response.helmet(options)
92
-
93
- return this
94
- }
95
-
96
- /**
97
- * Set the response status code.
98
- *
99
- * @param {number} code
100
- * @return {Response}
101
- */
102
- status(code) {
103
- this.#response.status(code)
104
-
105
- return this
106
- }
107
-
108
- /**
109
- * Remove some header from the response.
110
- *
111
- * @param {string} header
112
- * @return {Response}
113
- */
114
- removeHeader(header) {
115
- this.#response.removeHeader(header)
116
-
117
- return this
118
- }
119
-
120
- /**
121
- * Add some header to the response.
122
- *
123
- * @param {string} header
124
- * @param {any} value
125
- * @return {Response}
126
- */
127
- header(header, value) {
128
- this.#response.header(header, value)
129
-
130
- return this
131
- }
132
-
133
- /**
134
- * Only add some header to the response if it's not defined yet.
135
- *
136
- * @param {string} header
137
- * @param {any} value
138
- * @return {Response}
139
- */
140
- safeHeader(header, value) {
141
- if (!this.#response.hasHeader(header)) {
142
- this.#response.header(header, value)
143
- }
144
-
145
- return this
146
- }
147
-
148
- /**
149
- * Redirect the response to other url with different status code.
150
- *
151
- * @param {string} url
152
- * @param {number} [statusCode]
153
- * @return {void}
154
- */
155
- redirectTo(url, statusCode) {
156
- if (statusCode) {
157
- this.#response.redirect(statusCode, url)
158
-
159
- return
160
- }
161
-
162
- this.#response.redirect(url)
163
- }
164
-
165
- /**
166
- * Get the default fastify response object.
167
- *
168
- * @return {import('fastify').FastifyReply}
169
- */
170
- getFastifyResponse() {
171
- return this.#response
172
- }
173
- }
@@ -1,31 +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
-
10
- import { HttpException } from '#src/Exceptions/HttpException'
11
-
12
- export class BadGatewayException extends HttpException {
13
- /**
14
- * Creates a new instance of BadGatewayException.
15
- *
16
- * @example
17
- * throw new BadGatewayException()
18
- * This exception uses the 502 status code and the "E_BAD_GATEWAY_ERROR" code.
19
- *
20
- * @param {string} [content]
21
- * @param {string} [code]
22
- * @param {string|null} [help]
23
- */
24
- constructor(
25
- content = 'Bad gateway error',
26
- code = 'E_BAD_GATEWAY_ERROR',
27
- help = null,
28
- ) {
29
- super(content, 502, code, help)
30
- }
31
- }
@@ -1,31 +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
-
10
- import { HttpException } from '#src/Exceptions/HttpException'
11
-
12
- export class BadRequestException extends HttpException {
13
- /**
14
- * Creates a new instance of BadRequestException.
15
- *
16
- * @example
17
- * throw new BadRequestException()
18
- * This exception uses the 400 status code and the "E_BAD_REQUEST_ERROR" code.
19
- *
20
- * @param {string} [content]
21
- * @param {string} [code]
22
- * @param {string|null} [help]
23
- */
24
- constructor(
25
- content = 'Bad request error',
26
- code = 'E_BAD_REQUEST_ERROR',
27
- help = null,
28
- ) {
29
- super(content, 400, code, help)
30
- }
31
- }
@@ -1,31 +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
-
10
- import { HttpException } from '#src/Exceptions/HttpException'
11
-
12
- export class ForbiddenException extends HttpException {
13
- /**
14
- * Creates a new instance of ForbiddenException.
15
- *
16
- * @example
17
- * throw new ForbiddenException()
18
- * This exception uses the 403 status code and the "E_FORBIDDEN_ERROR" code.
19
- *
20
- * @param {string} [content]
21
- * @param {string} [code]
22
- * @param {string|null} [help]
23
- */
24
- constructor(
25
- content = 'Forbidden error',
26
- code = 'E_FORBIDDEN_ERROR',
27
- help = null,
28
- ) {
29
- super(content, 403, code, help)
30
- }
31
- }
@@ -1,33 +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
-
10
- import { Exception } from '@athenna/common'
11
-
12
- export class HttpException extends Exception {
13
- /**
14
- * Creates a new instance of HttpException.
15
- *
16
- * @example
17
- * throw new HttpException()
18
- * This exception uses the 500 status code and the "E_HTTP_ERROR" code.
19
- *
20
- * @param {string} [content]
21
- * @param {number} [status]
22
- * @param {string} [code]
23
- * @param {string|null} [help]
24
- */
25
- constructor(
26
- content = 'Http error',
27
- status = 500,
28
- code = 'E_HTTP_ERROR',
29
- help = null,
30
- ) {
31
- super(content, status, code, help)
32
- }
33
- }
@@ -1,31 +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
-
10
- import { HttpException } from '#src/Exceptions/HttpException'
11
-
12
- export class InternalServerException extends HttpException {
13
- /**
14
- * Creates a new instance of InternalServerException.
15
- *
16
- * @example
17
- * throw new InternalServerException()
18
- * This exception uses the 500 status code and the "E_INTERNAL_ERROR" code.
19
- *
20
- * @param {string} [content]
21
- * @param {string} [code]
22
- * @param {string|null} [help]
23
- */
24
- constructor(
25
- content = 'Internal server error',
26
- code = 'E_INTERNAL_ERROR',
27
- help = null,
28
- ) {
29
- super(content, 500, code, help)
30
- }
31
- }