-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
40 lines (35 loc) · 946 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
38
39
40
exports.handleCustomErrors = (err, req, res, next) => {
if(err.status && err.msg){
res.status(err.status).send({msg: err.msg})
} else {
next(err)
}
}
exports.handlePSQLNotFound = (err, req, res, next) => { //review
if(err.code === "23503") {
res.status(400).send({msg: "Bad request"})
} else {
next(err)
}
}
exports.handlePSQLentity = (err, req, res, next) => {
if (err.code === "23502"){
res.status(400).send({msg: "Bad request"})
} else {
next(err)
}
}
exports.handlePSQL = (err, req, res, next) => {
if (err.code === "22P02"){
res.status(400).send({msg: "Invalid input"})
} else {
next(err)
}
}
exports.handle500s = (err, req, res, next) => {
console.log(err)
res.status(500).send({msg: "Internal server error"})
}
exports.handle405s = (err, req, res, next) => {
res.status(405).send({msg: "Method not allowed"})
}