From 5cef705c02d14dafba266e8c4bd5dbf8e73a0fcf Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Wed, 20 Nov 2024 14:25:43 +0000 Subject: [PATCH] feat(handler): ignore if error code or name does not exist --- package-lock.json | 4 ++-- package.json | 2 +- src/handlers/HttpExceptionHandler.ts | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index fb1dde3..ba2fb3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/http", - "version": "5.4.0", + "version": "5.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/http", - "version": "5.4.0", + "version": "5.5.0", "license": "MIT", "devDependencies": { "@athenna/artisan": "^5.1.0", diff --git a/package.json b/package.json index b0fefec..253181c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/http", - "version": "5.4.0", + "version": "5.5.0", "description": "The Athenna Http server. Built on top of fastify.", "license": "MIT", "author": "João Lenon ", diff --git a/src/handlers/HttpExceptionHandler.ts b/src/handlers/HttpExceptionHandler.ts index ed4964e..05afe5d 100644 --- a/src/handlers/HttpExceptionHandler.ts +++ b/src/handlers/HttpExceptionHandler.ts @@ -32,7 +32,9 @@ export class HttpExceptionHandler { public async handle({ error, response }: ErrorContext): Promise { const body: any = { statusCode: Json.copy(error.statusCode) || Json.copy(error.status) || 500, - code: String.toSnakeCase(error.code || error.name).toUpperCase(), + code: String.toSnakeCase( + error.code || error.name || 'E_INTERNAL_SERVER' + ).toUpperCase(), name: Json.copy(error.name), message: Json.copy(error.message), details: Json.copy(error.details),