Skip to content

Commit 38409d9

Browse files
committed
Merge tag '1.4.7' into develop
* Fixed error return bug * Fixed problem of getting message when deleting message in chatwoot * Change in error return pattern
2 parents f74a7e8 + d344e51 commit 38409d9

File tree

4 files changed

+69
-61
lines changed

4 files changed

+69
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Fixed error return bug
66
* Fixed problem of getting message when deleting message in chatwoot
7+
* Change in error return pattern
78

89
# 1.4.6 (2023-07-26 17:54)
910

src/exceptions/400.exception.ts

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

33
export class BadRequestException {
44
constructor(...objectError: any[]) {
5-
console.log('BadRequestException', objectError);
65
throw {
76
status: HttpStatus.BAD_REQUEST,
87
error: 'Bad Request',

src/main.ts

Lines changed: 68 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,77 @@ import { HttpStatus, router } from './whatsapp/routers/index.router';
1414
import { waMonitor } from './whatsapp/whatsapp.module';
1515

1616
function initWA() {
17-
waMonitor.loadInstance();
17+
waMonitor.loadInstance();
1818
}
1919

2020
function bootstrap() {
21-
const logger = new Logger('SERVER');
22-
const app = express();
23-
24-
app.use(
25-
cors({
26-
origin(requestOrigin, callback) {
27-
const { ORIGIN } = configService.get<Cors>('CORS');
28-
!requestOrigin ? (requestOrigin = '*') : undefined;
29-
if (ORIGIN.indexOf(requestOrigin) !== -1) {
30-
return callback(null, true);
31-
}
32-
return callback(new Error('Not allowed by CORS'));
33-
},
34-
methods: [...configService.get<Cors>('CORS').METHODS],
35-
credentials: configService.get<Cors>('CORS').CREDENTIALS,
36-
}),
37-
urlencoded({ extended: true, limit: '136mb' }),
38-
json({ limit: '136mb' }),
39-
compression(),
40-
);
41-
42-
app.set('view engine', 'hbs');
43-
app.set('views', join(ROOT_DIR, 'views'));
44-
app.use(express.static(join(ROOT_DIR, 'public')));
45-
46-
app.use('/', router);
47-
48-
app.use(
49-
(err: Error, req: Request, res: Response, next: NextFunction) => {
50-
if (err) {
51-
return res.status(err['status'] || 500).json(err);
52-
}
53-
54-
next();
55-
},
56-
(req: Request, res: Response, next: NextFunction) => {
57-
const { method, url } = req;
58-
59-
res.status(HttpStatus.NOT_FOUND).json({
60-
status: HttpStatus.NOT_FOUND,
61-
message: `Cannot ${method.toUpperCase()} ${url}`,
62-
error: 'Not Found',
63-
});
64-
65-
next();
66-
},
67-
);
68-
69-
const httpServer = configService.get<HttpServer>('SERVER');
70-
71-
ServerUP.app = app;
72-
const server = ServerUP[httpServer.TYPE];
73-
74-
server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT));
75-
76-
initWA();
77-
78-
onUnexpectedError();
21+
const logger = new Logger('SERVER');
22+
const app = express();
23+
24+
app.use(
25+
cors({
26+
origin(requestOrigin, callback) {
27+
const { ORIGIN } = configService.get<Cors>('CORS');
28+
!requestOrigin ? (requestOrigin = '*') : undefined;
29+
if (ORIGIN.indexOf(requestOrigin) !== -1) {
30+
return callback(null, true);
31+
}
32+
return callback(new Error('Not allowed by CORS'));
33+
},
34+
methods: [...configService.get<Cors>('CORS').METHODS],
35+
credentials: configService.get<Cors>('CORS').CREDENTIALS,
36+
}),
37+
urlencoded({ extended: true, limit: '136mb' }),
38+
json({ limit: '136mb' }),
39+
compression(),
40+
);
41+
42+
app.set('view engine', 'hbs');
43+
app.set('views', join(ROOT_DIR, 'views'));
44+
app.use(express.static(join(ROOT_DIR, 'public')));
45+
46+
app.use('/', router);
47+
48+
app.use(
49+
(err: Error, req: Request, res: Response, next: NextFunction) => {
50+
if (err) {
51+
return res.status(err['status'] || 500).json({
52+
status: 'ERROR',
53+
error: err['error'] || 'Internal Server Error',
54+
response: {
55+
message: err['message'] || 'Internal Server Error',
56+
},
57+
}
58+
);
59+
}
60+
61+
next();
62+
},
63+
(req: Request, res: Response, next: NextFunction) => {
64+
const { method, url } = req;
65+
66+
res.status(HttpStatus.NOT_FOUND).json({
67+
status: HttpStatus.NOT_FOUND,
68+
error: 'Not Found',
69+
response: {
70+
message: `Cannot ${method.toUpperCase()} ${url}`,
71+
},
72+
});
73+
74+
next();
75+
},
76+
);
77+
78+
const httpServer = configService.get<HttpServer>('SERVER');
79+
80+
ServerUP.app = app;
81+
const server = ServerUP[httpServer.TYPE];
82+
83+
server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT));
84+
85+
initWA();
86+
87+
onUnexpectedError();
7988
}
8089

8190
bootstrap();

src/whatsapp/services/chatwoot.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ export class ChatwootService {
930930
}
931931

932932
public async receiveWebhook(instance: InstanceDto, body: any) {
933-
console.log(body);
934933
try {
935934
this.logger.verbose('receive webhook to chatwoot instance: ' + instance.instanceName);
936935
const client = await this.clientCw(instance);

0 commit comments

Comments
 (0)