@athenna/http 3.0.6 → 3.0.8

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": "3.0.6",
3
+ "version": "3.0.8",
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>",
@@ -57,11 +57,11 @@
57
57
  "fastify": "4.9.2"
58
58
  },
59
59
  "devDependencies": {
60
- "@athenna/artisan": "3.0.6",
61
- "@athenna/common": "3.0.0",
62
- "@athenna/config": "3.0.2",
63
- "@athenna/ioc": "3.0.0",
64
- "@athenna/logger": "3.0.5",
60
+ "@athenna/artisan": "3.0.8",
61
+ "@athenna/common": "3.0.2",
62
+ "@athenna/config": "3.0.4",
63
+ "@athenna/ioc": "3.0.2",
64
+ "@athenna/logger": "3.0.7",
65
65
  "@fastify/cors": "8.1.1",
66
66
  "@fastify/helmet": "10.0.2",
67
67
  "@fastify/rate-limit": "7.5.0",
@@ -7,9 +7,9 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
 
10
- import { Log } from '@athenna/logger'
11
10
  import { Config } from '@athenna/config'
12
- import { Exception, String } from '@athenna/common'
11
+ import { String } from '@athenna/common'
12
+ import { Log, Logger } from '@athenna/logger'
13
13
 
14
14
  export class HttpExceptionHandler {
15
15
  /**
@@ -61,8 +61,6 @@ export class HttpExceptionHandler {
61
61
  delete body.stack
62
62
  }
63
63
 
64
- response.status(statusCode).send(body)
65
-
66
64
  if (
67
65
  this.ignoreCodes.includes(code) ||
68
66
  this.ignoreStatuses.includes(statusCode)
@@ -70,20 +68,20 @@ export class HttpExceptionHandler {
70
68
  return
71
69
  }
72
70
 
73
- if (error.prettify) {
74
- const prettyError = await error.prettify()
75
-
76
- Log.channel('exception').error(prettyError.concat('\n'))
71
+ const logger = Config.exists('logging.channels.exception')
72
+ ? Log.channel('exception')
73
+ : Logger.getConsoleLogger({
74
+ level: 'trace',
75
+ streamType: 'stderr',
76
+ formatter: 'none',
77
+ })
77
78
 
78
- return
79
+ if (!error.prettify) {
80
+ error = error.toAthennaException()
79
81
  }
80
82
 
81
- const exception = new Exception(body.message, body.statusCode, body.code)
82
-
83
- exception.stack = error.stack
84
-
85
- const prettyError = await exception.prettify()
83
+ logger.error((await error.prettify()).concat('\n'))
86
84
 
87
- Log.channel('exception').error(prettyError.concat('\n'))
85
+ return response.status(statusCode).send(body)
88
86
  }
89
87
  }
@@ -9,7 +9,7 @@
9
9
 
10
10
  import rTracer from 'cls-rtracer'
11
11
 
12
- import { Log } from '@athenna/logger'
12
+ import { Log, Logger } from '@athenna/logger'
13
13
  import { Config } from '@athenna/config'
14
14
  import { Server } from '#src/Facades/Server'
15
15
  import { Module, Path } from '@athenna/common'
@@ -184,6 +184,15 @@ export class HttpKernel {
184
184
  return
185
185
  }
186
186
 
187
- Server.use(async ctx => Log.channel('request').info(ctx), 'terminate')
187
+ Server.use(async ctx => {
188
+ const logger = Config.exists('logging.channels.request')
189
+ ? Log.channel('request')
190
+ : Logger.getConsoleLogger({
191
+ level: 'trace',
192
+ formatter: 'none',
193
+ })
194
+
195
+ logger.info(ctx)
196
+ }, 'terminate')
188
197
  }
189
198
  }
@@ -17,7 +17,7 @@ export class ControllerProvider extends ServiceProvider {
17
17
  * @return {Promise<void>}
18
18
  */
19
19
  async boot() {
20
- const path = Path.app('Http/Controllers')
20
+ const path = Path.http('Controllers')
21
21
  const subAlias = 'App/Http/Controllers'
22
22
 
23
23
  const controllers = await Module.getAllFromWithAlias(path, subAlias)
@@ -17,7 +17,7 @@ export class MiddlewareProvider extends ServiceProvider {
17
17
  * @return {Promise<void>}
18
18
  */
19
19
  async boot() {
20
- const path = Path.app('Http/Middlewares')
20
+ const path = Path.http('Middlewares')
21
21
  const subAlias = 'App/Http/Middlewares'
22
22
 
23
23
  const middlewares = await Module.getAllFromWithAlias(path, subAlias)