-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
37 lines (33 loc) · 843 Bytes
/
errors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
exports.handle404 = (err, req, res, next) => {
if (err.status === 404) {
res.status(404).send({ msg: 'Route not Found' });
} else {
next(err);
}
};
exports.handle405 = (req, res, next) => {
res.status(405).send({ msg: 'method not allowed' });
};
exports.handle400 = (err, req, res, next) => {
input = {
nullValue: 'invalid value',
};
if (err.code === '23502' || err.code === '42703' || err.code === '22P02') {
res.status(400).send({ msg: input.nullValue });
} else {
next(err);
}
};
exports.handle422 = (err, req, res, next) => {
input = {
nullValue: 'null or missing value',
};
if (err.code === '23505') {
res.status(422).send({ msg: input.nullValue });
} else {
next(err);
}
};
exports.handle500 = (err, req, res, next) => {
res.status(500).send('Internal server error');
};