Skip to content

Commit

Permalink
refactor: remove defaultErrorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Mar 30, 2022
1 parent 642d513 commit 95304ac
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 79 deletions.
21 changes: 0 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
"dependencies": {
"@athenna/config": "1.0.5",
"@athenna/ioc": "1.0.6",
"@athenna/logger": "1.0.4",
"@secjs/utils": "1.8.0",
"fastify": "3.27.4",
"reflect-metadata": "0.1.13",
Expand Down
2 changes: 0 additions & 2 deletions src/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import fastify, { FastifyInstance, PrintRoutesOptions } from 'fastify'

import { FastifyHandler } from './Utils/FastifyHandler'
import { HttpMethodTypes } from './Contracts/HttpMethodTypes'
import { defaultErrorHandler } from './Utils/defaultErrorHandler'
import { HandlerContract } from './Contracts/Context/HandlerContract'
import { MiddlewareTypesContract } from './Contracts/MiddlewareTypesContract'
import { ErrorHandlerContract } from './Contracts/Context/Error/ErrorHandlerContract'
Expand All @@ -24,7 +23,6 @@ export class Http {

constructor() {
this.server = fastify()
this.setErrorHandler(defaultErrorHandler)
}

setErrorHandler(handler: ErrorHandlerContract) {
Expand Down
42 changes: 0 additions & 42 deletions src/Utils/defaultErrorHandler.ts

This file was deleted.

8 changes: 2 additions & 6 deletions tests/Unit/HttpTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ describe('\n HttpTest', () => {
await errorHttp.close()

expect(response.status).toBe(400)
expect(response.body.code).toStrictEqual('BAD_REQUEST_ERROR')
expect(response.body.path).toStrictEqual('/test')
expect(response.body.method).toStrictEqual('GET')
expect(response.body.status).toStrictEqual('ERROR')
expect(response.body.statusCode).toStrictEqual(400)
expect(response.body.error.name).toStrictEqual('BadRequestException')
expect(response.body.error.message).toStrictEqual('Testing')
expect(response.body.code).toStrictEqual('BAD_REQUEST_ERROR')
expect(response.body.message).toStrictEqual('Testing')
})

it('should be able to register a new route with a intercept middleware', async () => {
Expand Down
10 changes: 3 additions & 7 deletions tests/Unit/RouteTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,10 @@ describe('\n RouteTest', () => {
const response = await supertest('http://localhost:3044').get('/v1/test')

expect(response.status).toBe(400)
expect(response.body.midHandler).toBeFalsy()
expect(response.body.code).toStrictEqual('BAD_REQUEST_ERROR')
expect(response.body.path).toStrictEqual('/v1/test')
expect(response.body.method).toStrictEqual('GET')
expect(response.body.status).toStrictEqual('ERROR')
expect(response.body.statusCode).toStrictEqual(400)
expect(response.body.error.name).toStrictEqual('BadRequestException')
expect(response.body.error.message).toStrictEqual('Testing')
expect(response.body.code).toStrictEqual('BAD_REQUEST_ERROR')
expect(response.body.error).toStrictEqual('Bad Request')
expect(response.body.message).toStrictEqual('Testing')
}
{
const response = await supertest('http://localhost:3044').patch('/v1/test')
Expand Down

0 comments on commit 95304ac

Please sign in to comment.