@athenna/http 1.3.4 → 1.3.7

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.3.4",
3
+ "version": "1.3.7",
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>",
@@ -49,8 +49,8 @@
49
49
  "#tests/*": "./tests/*.js"
50
50
  },
51
51
  "dependencies": {
52
- "@athenna/ioc": "1.1.7",
53
- "@athenna/logger": "1.2.2",
52
+ "@athenna/ioc": "1.1.8",
53
+ "@athenna/logger": "1.2.3",
54
54
  "@secjs/utils": "1.9.3",
55
55
  "fastify": "3.27.4",
56
56
  "fastify-cors": "6.0.3",
@@ -1,3 +1,4 @@
1
+ import { Log } from '@athenna/logger'
1
2
  import { Config, Exception, String } from '@secjs/utils'
2
3
 
3
4
  export class HttpExceptionHandler {
@@ -58,7 +59,7 @@ export class HttpExceptionHandler {
58
59
  if (error.prettify) {
59
60
  const prettyError = await error.prettify()
60
61
 
61
- process.stderr.write(prettyError.concat('\n'))
62
+ Log.channel('exception').error(prettyError.concat('\n'))
62
63
 
63
64
  return
64
65
  }
@@ -69,6 +70,6 @@ export class HttpExceptionHandler {
69
70
  body.code,
70
71
  ).prettify()
71
72
 
72
- process.stderr.write(prettyError.concat('\n'))
73
+ Log.channel('exception').error(prettyError.concat('\n'))
73
74
  }
74
75
  }
package/src/index.d.ts CHANGED
@@ -93,7 +93,7 @@ export class HttpExceptionHandler {
93
93
  *
94
94
  * @param ctx
95
95
  */
96
- handle({ error, response }: { error: any; response: any }): Promise<any>
96
+ handle(ctx: ErrorContextContract): Promise<any>
97
97
  }
98
98
 
99
99
  export class Http {
@@ -103,7 +103,7 @@ export class Http {
103
103
  * @param {any} handler
104
104
  * @return {Http}
105
105
  */
106
- setErrorHandler(handler: any): Http
106
+ setErrorHandler(handler: ErrorHandlerContract): Http
107
107
 
108
108
  /**
109
109
  * Register a new fastify plugin.
@@ -198,7 +198,7 @@ export class Http {
198
198
  * @param {any} [middlewares]
199
199
  * @return {void}
200
200
  */
201
- route(url: string, methods: string[], handler: any, middlewares?: any): void
201
+ route(url: string, methods: string[], handler: HandlerContract, middlewares?: any): void
202
202
 
203
203
  /**
204
204
  * Add a new GET route to the http server.
@@ -208,7 +208,7 @@ export class Http {
208
208
  * @param {any} [middlewares]
209
209
  * @return {void}
210
210
  */
211
- get(url: string, handler: any, middlewares?: any): void
211
+ get(url: string, handler: HandlerContract, middlewares?: any): void
212
212
 
213
213
  /**
214
214
  * Add a new HEAD route to the http server.
@@ -218,7 +218,7 @@ export class Http {
218
218
  * @param {any} [middlewares]
219
219
  * @return {void}
220
220
  */
221
- head(url: string, handler: any, middlewares?: any): void
221
+ head(url: string, handler: HandlerContract, middlewares?: any): void
222
222
 
223
223
  /**
224
224
  * Add a new POST route to the http server.
@@ -228,7 +228,7 @@ export class Http {
228
228
  * @param {any} [middlewares]
229
229
  * @return {void}
230
230
  */
231
- post(url: string, handler: any, middlewares?: any): void
231
+ post(url: string, handler: HandlerContract, middlewares?: any): void
232
232
 
233
233
  /**
234
234
  * Add a new PUT route to the http server.
@@ -238,7 +238,7 @@ export class Http {
238
238
  * @param {any} [middlewares]
239
239
  * @return {void}
240
240
  */
241
- put(url: string, handler: any, middlewares?: any): void
241
+ put(url: string, handler: HandlerContract, middlewares?: any): void
242
242
 
243
243
  /**
244
244
  * Add a new PATCH route to the http server.
@@ -248,7 +248,7 @@ export class Http {
248
248
  * @param {any} [middlewares]
249
249
  * @return {void}
250
250
  */
251
- patch(url: string, handler: any, middlewares?: any): void
251
+ patch(url: string, handler: HandlerContract, middlewares?: any): void
252
252
 
253
253
  /**
254
254
  * Add a new DELETE route to the http server.
@@ -258,7 +258,7 @@ export class Http {
258
258
  * @param {any} [middlewares]
259
259
  * @return {void}
260
260
  */
261
- delete(url: string, handler: any, middlewares?: any): void
261
+ delete(url: string, handler: HandlerContract, middlewares?: any): void
262
262
 
263
263
  /**
264
264
  * Add a new OPTIONS route to the http server.
@@ -268,7 +268,7 @@ export class Http {
268
268
  * @param {any} [middlewares]
269
269
  * @return {void}
270
270
  */
271
- options(url: string, handler: any, middlewares?: any): void
271
+ options(url: string, handler: HandlerContract, middlewares?: any): void
272
272
  }
273
273
 
274
274
  declare module Router {
@@ -419,7 +419,7 @@ declare module Router {
419
419
  * @param {string|any} handler
420
420
  * @return {Route}
421
421
  */
422
- route(url: string, methods: string[], handler: string | any): Route
422
+ route(url: string, methods: string[], handler: string | HandlerContract): Route
423
423
 
424
424
  /**
425
425
  * Creates a new route group.
@@ -455,7 +455,7 @@ declare module Router {
455
455
  * @param {string|any} handler
456
456
  * @return {Route}
457
457
  */
458
- get(url: string, handler: string | any): Route
458
+ get(url: string, handler: string | HandlerContract): Route
459
459
 
460
460
  /**
461
461
  * Register a new head method route.
@@ -464,7 +464,7 @@ declare module Router {
464
464
  * @param {string|any} handler
465
465
  * @return {Route}
466
466
  */
467
- head(url: string, handler: string | any): Route
467
+ head(url: string, handler: string | HandlerContract): Route
468
468
 
469
469
  /**
470
470
  * Register a new post method route.
@@ -473,7 +473,7 @@ declare module Router {
473
473
  * @param {string|any} handler
474
474
  * @return {Route}
475
475
  */
476
- post(url: string, handler: string | any): Route
476
+ post(url: string, handler: string | HandlerContract): Route
477
477
 
478
478
  /**
479
479
  * Register a new put method route.
@@ -482,7 +482,7 @@ declare module Router {
482
482
  * @param {string|any} handler
483
483
  * @return {Route}
484
484
  */
485
- put(url: string, handler: string | any): Route
485
+ put(url: string, handler: string | HandlerContract): Route
486
486
 
487
487
  /**
488
488
  * Register a new patch method route.
@@ -491,7 +491,7 @@ declare module Router {
491
491
  * @param {string|any} handler
492
492
  * @return {Route}
493
493
  */
494
- patch(url: string, handler: string | any): Route
494
+ patch(url: string, handler: string | HandlerContract): Route
495
495
 
496
496
  /**
497
497
  * Register a new delete method route.
@@ -500,7 +500,7 @@ declare module Router {
500
500
  * @param {string|any} handler
501
501
  * @return {Route}
502
502
  */
503
- delete(url: string, handler: string | any): Route
503
+ delete(url: string, handler: string | HandlerContract): Route
504
504
 
505
505
  /**
506
506
  * Register a new options method route.
@@ -509,7 +509,7 @@ declare module Router {
509
509
  * @param {string|any} handler
510
510
  * @return {Route}
511
511
  */
512
- options(url: string, handler: string | any): Route
512
+ options(url: string, handler: string | HandlerContract): Route
513
513
 
514
514
  /**
515
515
  * Register a new route with all methods.
@@ -518,7 +518,7 @@ declare module Router {
518
518
  * @param {string|any} handler
519
519
  * @return {Route}
520
520
  */
521
- any(url: string, handler: string | any): Route
521
+ any(url: string, handler: string | HandlerContract): Route
522
522
 
523
523
  /**
524
524
  * Register all the routes inside the Server.