From 127d5b97c405c67c5f66deb32c902e2c529ff859 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Thu, 27 Jul 2023 08:36:18 -0300 Subject: [PATCH] fix: fixed error return bug --- CHANGELOG.md | 6 +++ src/exceptions/400.exception.ts | 1 + src/main.ts | 43 +++---------------- src/whatsapp/abstract/abstract.router.ts | 12 +++--- .../controllers/settings.controller.ts | 1 - src/whatsapp/repository/repository.manager.ts | 1 - 6 files changed, 20 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a5235d4..5013ceaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.4.7 (2023-07-26 17:54) + +### Fixed + +* Fixed error return bug + # 1.4.6 (2023-07-26 17:54) ### Fixed diff --git a/src/exceptions/400.exception.ts b/src/exceptions/400.exception.ts index 833295c1..a9256bcb 100644 --- a/src/exceptions/400.exception.ts +++ b/src/exceptions/400.exception.ts @@ -2,6 +2,7 @@ import { HttpStatus } from '../whatsapp/routers/index.router'; export class BadRequestException { constructor(...objectError: any[]) { + console.log('BadRequestException', objectError); throw { status: HttpStatus.BAD_REQUEST, error: 'Bad Request', diff --git a/src/main.ts b/src/main.ts index b0d2e03e..6e15f84d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,18 +1,15 @@ -import 'express-async-errors'; - -// import * as Sentry from '@sentry/node'; import compression from 'compression'; +import { configService, Cors, HttpServer } from './config/env.config'; import cors from 'cors'; import express, { json, NextFunction, Request, Response, urlencoded } from 'express'; import { join } from 'path'; - -import { configService, Cors, HttpServer } from './config/env.config'; import { onUnexpectedError } from './config/error.config'; import { Logger } from './config/logger.config'; import { ROOT_DIR } from './config/path.config'; -import { ServerUP } from './utils/server-up'; -import { HttpStatus, router } from './whatsapp/routers/index.router'; import { waMonitor } from './whatsapp/whatsapp.module'; +import { HttpStatus, router } from './whatsapp/routers/index.router'; +import 'express-async-errors'; +import { ServerUP } from './utils/server-up'; function initWA() { waMonitor.loadInstance(); @@ -22,27 +19,6 @@ function bootstrap() { const logger = new Logger('SERVER'); const app = express(); - // Sentry.init({ - // dsn: '', - // integrations: [ - // // enable HTTP calls tracing - // new Sentry.Integrations.Http({ tracing: true }), - // // enable Express.js middleware tracing - // new Sentry.Integrations.Express({ app }), - // // Automatically instrument Node.js libraries and frameworks - // ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(), - // ], - - // // Set tracesSampleRate to 1.0 to capture 100% - // // of transactions for performance monitoring. - // // We recommend adjusting this value in production - // tracesSampleRate: 1.0, - // }); - - // app.use(Sentry.Handlers.requestHandler()); - - // app.use(Sentry.Handlers.tracingHandler()); - app.use( cors({ origin(requestOrigin, callback) { @@ -67,18 +43,13 @@ function bootstrap() { app.use('/', router); - // app.use(Sentry.Handlers.errorHandler()); - - // app.use(function onError(err, req, res, next) { - // res.statusCode = 500; - // res.end(res.sentry + '\n'); - // }); - app.use( - (err: Error, req: Request, res: Response) => { + (err: Error, req: Request, res: Response, next: NextFunction) => { if (err) { return res.status(err['status'] || 500).json(err); } + + next(); }, (req: Request, res: Response, next: NextFunction) => { const { method, url } = req; diff --git a/src/whatsapp/abstract/abstract.router.ts b/src/whatsapp/abstract/abstract.router.ts index 136b946a..170b06fb 100644 --- a/src/whatsapp/abstract/abstract.router.ts +++ b/src/whatsapp/abstract/abstract.router.ts @@ -6,7 +6,7 @@ import { validate } from 'jsonschema'; import { Logger } from '../../config/logger.config'; import { BadRequestException } from '../../exceptions'; -import { GetParticipant, GroupInvite, GroupJid } from '../dto/group.dto'; +import { GetParticipant, GroupInvite } from '../dto/group.dto'; import { InstanceDto } from '../dto/instance.dto'; type DataValidate = { @@ -105,7 +105,7 @@ export abstract class RouterBroker { const body = request.body; let groupJid = body?.groupJid; - + if (!groupJid) { if (request.query?.groupJid) { groupJid = request.query.groupJid; @@ -113,15 +113,15 @@ export abstract class RouterBroker { throw new BadRequestException('The group id needs to be informed in the query', 'ex: "groupJid=120362@g.us"'); } } - + if (!groupJid.endsWith('@g.us')) { groupJid = groupJid + '@g.us'; } - + Object.assign(body, { - groupJid: groupJid + groupJid: groupJid, }); - + const ref = new ClassRef(); Object.assign(ref, body); diff --git a/src/whatsapp/controllers/settings.controller.ts b/src/whatsapp/controllers/settings.controller.ts index 32713b1f..1a8baafc 100644 --- a/src/whatsapp/controllers/settings.controller.ts +++ b/src/whatsapp/controllers/settings.controller.ts @@ -12,7 +12,6 @@ export class SettingsController { constructor(private readonly settingsService: SettingsService) {} public async createSettings(instance: InstanceDto, data: SettingsDto) { - logger.verbose('requested createSettings from ' + instance.instanceName + ' instance'); return this.settingsService.create(instance, data); diff --git a/src/whatsapp/repository/repository.manager.ts b/src/whatsapp/repository/repository.manager.ts index ae02849f..e1292329 100644 --- a/src/whatsapp/repository/repository.manager.ts +++ b/src/whatsapp/repository/repository.manager.ts @@ -109,7 +109,6 @@ export class RepositoryBroker { this.logger.verbose('creating temp dir: ' + tempDir); fs.mkdirSync(tempDir, { recursive: true }); } - } catch (error) { this.logger.error(error); }