-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorHandler.js
More file actions
42 lines (41 loc) · 1.28 KB
/
errorHandler.js
File metadata and controls
42 lines (41 loc) · 1.28 KB
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
41
42
const {constants}=require("../constants");
const errorHandler=(err,req,res,next)=>{
const statusCode=res.statusCode? res.statusCode:500;
switch(statusCode){
case constants.VALIDATION_ERROR:
res.json({
title:"Validation Failed",
message: err.message,
stackTrace:err.stack
});
break;
case constants.NOT_FOUND:
res.json({
title:"Not Found",
message: err.message,
stackTrace:err.stack
});
case constants.UNAUTHORIZED:
res.json({
title:"Unauthorized",
message: err.message,
stackTrace:err.stack
});
case constants.FORBIDDEN:
res.json({
title:"Forbidden",
message: err.message,
stackTrace:err.stack
});
case constants.SERVER_ERROR:
res.json({
title:"Server Error",
message: err.message,
stackTrace:err.stack
});
default:
console.log("No error,All good!");
break;
}
};
module.exports=errorHandler;