diff --git a/src/exceptions/400.exception.ts b/src/exceptions/400.exception.ts index a9256bcb..833295c1 100644 --- a/src/exceptions/400.exception.ts +++ b/src/exceptions/400.exception.ts @@ -2,7 +2,6 @@ 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 a5b7fe8c..8a14f746 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,68 +14,77 @@ import { HttpStatus, router } from './whatsapp/routers/index.router'; import { waMonitor } from './whatsapp/whatsapp.module'; function initWA() { - waMonitor.loadInstance(); + waMonitor.loadInstance(); } function bootstrap() { - const logger = new Logger('SERVER'); - const app = express(); + const logger = new Logger('SERVER'); + const app = express(); - app.use( - cors({ - origin(requestOrigin, callback) { - const { ORIGIN } = configService.get('CORS'); - !requestOrigin ? (requestOrigin = '*') : undefined; - if (ORIGIN.indexOf(requestOrigin) !== -1) { - return callback(null, true); - } - return callback(new Error('Not allowed by CORS')); - }, - methods: [...configService.get('CORS').METHODS], - credentials: configService.get('CORS').CREDENTIALS, - }), - urlencoded({ extended: true, limit: '136mb' }), - json({ limit: '136mb' }), - compression(), - ); + app.use( + cors({ + origin(requestOrigin, callback) { + const { ORIGIN } = configService.get('CORS'); + !requestOrigin ? (requestOrigin = '*') : undefined; + if (ORIGIN.indexOf(requestOrigin) !== -1) { + return callback(null, true); + } + return callback(new Error('Not allowed by CORS')); + }, + methods: [...configService.get('CORS').METHODS], + credentials: configService.get('CORS').CREDENTIALS, + }), + urlencoded({ extended: true, limit: '136mb' }), + json({ limit: '136mb' }), + compression(), + ); - app.set('view engine', 'hbs'); - app.set('views', join(ROOT_DIR, 'views')); - app.use(express.static(join(ROOT_DIR, 'public'))); + app.set('view engine', 'hbs'); + app.set('views', join(ROOT_DIR, 'views')); + app.use(express.static(join(ROOT_DIR, 'public'))); - app.use('/', router); + app.use('/', router); - app.use( - (err: Error, req: Request, res: Response, next: NextFunction) => { - if (err) { - return res.status(err['status'] || 500).json(err); - } + app.use( + (err: Error, req: Request, res: Response, next: NextFunction) => { + if (err) { + return res.status(err['status'] || 500).json({ + status: 'ERROR', + error: err['error'] || 'Internal Server Error', + response: { + message: err['message'] || 'Internal Server Error', + }, + } + ); + } - next(); - }, - (req: Request, res: Response, next: NextFunction) => { - const { method, url } = req; + next(); + }, + (req: Request, res: Response, next: NextFunction) => { + const { method, url } = req; - res.status(HttpStatus.NOT_FOUND).json({ - status: HttpStatus.NOT_FOUND, - message: `Cannot ${method.toUpperCase()} ${url}`, - error: 'Not Found', - }); + res.status(HttpStatus.NOT_FOUND).json({ + status: HttpStatus.NOT_FOUND, + error: 'Not Found', + response: { + message: `Cannot ${method.toUpperCase()} ${url}`, + }, + }); - next(); - }, - ); + next(); + }, + ); - const httpServer = configService.get('SERVER'); + const httpServer = configService.get('SERVER'); - ServerUP.app = app; - const server = ServerUP[httpServer.TYPE]; + ServerUP.app = app; + const server = ServerUP[httpServer.TYPE]; - server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT)); + server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT)); - initWA(); + initWA(); - onUnexpectedError(); + onUnexpectedError(); } bootstrap(); diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 283a4198..23efc66f 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -930,7 +930,6 @@ export class ChatwootService { } public async receiveWebhook(instance: InstanceDto, body: any) { - console.log(body); try { this.logger.verbose('receive webhook to chatwoot instance: ' + instance.instanceName); const client = await this.clientCw(instance);