-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.js
More file actions
29 lines (27 loc) · 726 Bytes
/
errors.js
File metadata and controls
29 lines (27 loc) · 726 Bytes
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
exports.pathError = (req, res) => {
res.status(404).send({ msg: 'not found' });
};
exports.generalError = (err, req, res, next) => {
if (err.status && err.msg) {
res.status(err.status).send({ msg: err.msg });
} else {
next(err);
}
};
exports.Error400 = (err, req, res, next) => {
if (err.code === '22P02' || err.code === '23502' || err.code === '42703') {
res.status(400).send({ msg: 'Bad request' });
} else {
next(err);
}
};
exports.Error404 = (err, req, res, next) => {
if (err.code === '23503') {
res.status(404).send({ msg: 'Not found' });
} else {
next(err);
}
};
exports.Error500 = (err, req, respresonse) => {
res.status(500).send({ msg: 'Internal server error!' });
};