fix: fixed error return bug

This commit is contained in:
Davidson Gomes 2023-07-27 08:36:18 -03:00
parent 7ef1c097e8
commit 127d5b97c4
6 changed files with 20 additions and 44 deletions

View File

@ -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) # 1.4.6 (2023-07-26 17:54)
### Fixed ### Fixed

View File

@ -2,6 +2,7 @@ import { HttpStatus } from '../whatsapp/routers/index.router';
export class BadRequestException { export class BadRequestException {
constructor(...objectError: any[]) { constructor(...objectError: any[]) {
console.log('BadRequestException', objectError);
throw { throw {
status: HttpStatus.BAD_REQUEST, status: HttpStatus.BAD_REQUEST,
error: 'Bad Request', error: 'Bad Request',

View File

@ -1,18 +1,15 @@
import 'express-async-errors';
// import * as Sentry from '@sentry/node';
import compression from 'compression'; import compression from 'compression';
import { configService, Cors, HttpServer } from './config/env.config';
import cors from 'cors'; import cors from 'cors';
import express, { json, NextFunction, Request, Response, urlencoded } from 'express'; import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
import { join } from 'path'; import { join } from 'path';
import { configService, Cors, HttpServer } from './config/env.config';
import { onUnexpectedError } from './config/error.config'; import { onUnexpectedError } from './config/error.config';
import { Logger } from './config/logger.config'; import { Logger } from './config/logger.config';
import { ROOT_DIR } from './config/path.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 { 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() { function initWA() {
waMonitor.loadInstance(); waMonitor.loadInstance();
@ -22,27 +19,6 @@ function bootstrap() {
const logger = new Logger('SERVER'); const logger = new Logger('SERVER');
const app = express(); 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( app.use(
cors({ cors({
origin(requestOrigin, callback) { origin(requestOrigin, callback) {
@ -67,18 +43,13 @@ function bootstrap() {
app.use('/', router); 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( app.use(
(err: Error, req: Request, res: Response) => { (err: Error, req: Request, res: Response, next: NextFunction) => {
if (err) { if (err) {
return res.status(err['status'] || 500).json(err); return res.status(err['status'] || 500).json(err);
} }
next();
}, },
(req: Request, res: Response, next: NextFunction) => { (req: Request, res: Response, next: NextFunction) => {
const { method, url } = req; const { method, url } = req;

View File

@ -6,7 +6,7 @@ import { validate } from 'jsonschema';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../config/logger.config';
import { BadRequestException } from '../../exceptions'; 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'; import { InstanceDto } from '../dto/instance.dto';
type DataValidate<T> = { type DataValidate<T> = {
@ -119,7 +119,7 @@ export abstract class RouterBroker {
} }
Object.assign(body, { Object.assign(body, {
groupJid: groupJid groupJid: groupJid,
}); });
const ref = new ClassRef(); const ref = new ClassRef();

View File

@ -12,7 +12,6 @@ export class SettingsController {
constructor(private readonly settingsService: SettingsService) {} constructor(private readonly settingsService: SettingsService) {}
public async createSettings(instance: InstanceDto, data: SettingsDto) { public async createSettings(instance: InstanceDto, data: SettingsDto) {
logger.verbose('requested createSettings from ' + instance.instanceName + ' instance'); logger.verbose('requested createSettings from ' + instance.instanceName + ' instance');
return this.settingsService.create(instance, data); return this.settingsService.create(instance, data);

View File

@ -109,7 +109,6 @@ export class RepositoryBroker {
this.logger.verbose('creating temp dir: ' + tempDir); this.logger.verbose('creating temp dir: ' + tempDir);
fs.mkdirSync(tempDir, { recursive: true }); fs.mkdirSync(tempDir, { recursive: true });
} }
} catch (error) { } catch (error) {
this.logger.error(error); this.logger.error(error);
} }