Skip to content

Commit 127d5b9

Browse files
committed
fix: fixed error return bug
1 parent 7ef1c09 commit 127d5b9

File tree

6 files changed

+20
-44
lines changed

6 files changed

+20
-44
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.4.7 (2023-07-26 17:54)
2+
3+
### Fixed
4+
5+
* Fixed error return bug
6+
17
# 1.4.6 (2023-07-26 17:54)
28

39
### Fixed

src/exceptions/400.exception.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpStatus } from '../whatsapp/routers/index.router';
22

33
export class BadRequestException {
44
constructor(...objectError: any[]) {
5+
console.log('BadRequestException', objectError);
56
throw {
67
status: HttpStatus.BAD_REQUEST,
78
error: 'Bad Request',

src/main.ts

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import 'express-async-errors';
2-
3-
// import * as Sentry from '@sentry/node';
41
import compression from 'compression';
2+
import { configService, Cors, HttpServer } from './config/env.config';
53
import cors from 'cors';
64
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
75
import { join } from 'path';
8-
9-
import { configService, Cors, HttpServer } from './config/env.config';
106
import { onUnexpectedError } from './config/error.config';
117
import { Logger } from './config/logger.config';
128
import { ROOT_DIR } from './config/path.config';
13-
import { ServerUP } from './utils/server-up';
14-
import { HttpStatus, router } from './whatsapp/routers/index.router';
159
import { waMonitor } from './whatsapp/whatsapp.module';
10+
import { HttpStatus, router } from './whatsapp/routers/index.router';
11+
import 'express-async-errors';
12+
import { ServerUP } from './utils/server-up';
1613

1714
function initWA() {
1815
waMonitor.loadInstance();
@@ -22,27 +19,6 @@ function bootstrap() {
2219
const logger = new Logger('SERVER');
2320
const app = express();
2421

25-
// Sentry.init({
26-
// dsn: '',
27-
// integrations: [
28-
// // enable HTTP calls tracing
29-
// new Sentry.Integrations.Http({ tracing: true }),
30-
// // enable Express.js middleware tracing
31-
// new Sentry.Integrations.Express({ app }),
32-
// // Automatically instrument Node.js libraries and frameworks
33-
// ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
34-
// ],
35-
36-
// // Set tracesSampleRate to 1.0 to capture 100%
37-
// // of transactions for performance monitoring.
38-
// // We recommend adjusting this value in production
39-
// tracesSampleRate: 1.0,
40-
// });
41-
42-
// app.use(Sentry.Handlers.requestHandler());
43-
44-
// app.use(Sentry.Handlers.tracingHandler());
45-
4622
app.use(
4723
cors({
4824
origin(requestOrigin, callback) {
@@ -67,18 +43,13 @@ function bootstrap() {
6743

6844
app.use('/', router);
6945

70-
// app.use(Sentry.Handlers.errorHandler());
71-
72-
// app.use(function onError(err, req, res, next) {
73-
// res.statusCode = 500;
74-
// res.end(res.sentry + '\n');
75-
// });
76-
7746
app.use(
78-
(err: Error, req: Request, res: Response) => {
47+
(err: Error, req: Request, res: Response, next: NextFunction) => {
7948
if (err) {
8049
return res.status(err['status'] || 500).json(err);
8150
}
51+
52+
next();
8253
},
8354
(req: Request, res: Response, next: NextFunction) => {
8455
const { method, url } = req;

src/whatsapp/abstract/abstract.router.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { validate } from 'jsonschema';
66

77
import { Logger } from '../../config/logger.config';
88
import { BadRequestException } from '../../exceptions';
9-
import { GetParticipant, GroupInvite, GroupJid } from '../dto/group.dto';
9+
import { GetParticipant, GroupInvite } from '../dto/group.dto';
1010
import { InstanceDto } from '../dto/instance.dto';
1111

1212
type DataValidate<T> = {
@@ -105,23 +105,23 @@ export abstract class RouterBroker {
105105
const body = request.body;
106106

107107
let groupJid = body?.groupJid;
108-
108+
109109
if (!groupJid) {
110110
if (request.query?.groupJid) {
111111
groupJid = request.query.groupJid;
112112
} else {
113113
throw new BadRequestException('The group id needs to be informed in the query', 'ex: "groupJid=120362@g.us"');
114114
}
115115
}
116-
116+
117117
if (!groupJid.endsWith('@g.us')) {
118118
groupJid = groupJid + '@g.us';
119119
}
120-
120+
121121
Object.assign(body, {
122-
groupJid: groupJid
122+
groupJid: groupJid,
123123
});
124-
124+
125125
const ref = new ClassRef();
126126

127127
Object.assign(ref, body);

src/whatsapp/controllers/settings.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class SettingsController {
1212
constructor(private readonly settingsService: SettingsService) {}
1313

1414
public async createSettings(instance: InstanceDto, data: SettingsDto) {
15-
1615
logger.verbose('requested createSettings from ' + instance.instanceName + ' instance');
1716

1817
return this.settingsService.create(instance, data);

src/whatsapp/repository/repository.manager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export class RepositoryBroker {
109109
this.logger.verbose('creating temp dir: ' + tempDir);
110110
fs.mkdirSync(tempDir, { recursive: true });
111111
}
112-
113112
} catch (error) {
114113
this.logger.error(error);
115114
}

0 commit comments

Comments
 (0)