-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorHandler.js
48 lines (47 loc) · 1.72 KB
/
errorHandler.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
41
42
43
44
45
46
47
48
import { logger } from './logging.js';
export function errorHandler(err, req, res, next) {
let errorType = err.type;
if (!errorType) {
logger.error("Error handler received an unknown type (500 return)", err);
res.status(500).json({ error: err });
return;
} else {
logger.error("Error handler received a known type", err);
}
errorType = errorType.trim();
switch (errorType) {
case "entity.too.large":
res.status(400).json({ errors: [`JSON input limit of ${err.limit} exceeded`] });
return;
case "invalidCredential":
res.status(400).json({ errors: [err.errors[0].message] });
return;
case "invalidProof":
if (err.errors) {
res.status(400).json({ errors: ["proof: " + err.errors[0].message] });
} else {
res.status(400).json({ errors: ["proof: invalid"] });
}
return;
case "missingDocument":
res.status(400).json({ errors: ["no credential supplied"] });
return;
case "missingProof":
res.status(400).json({ errors: ["no proof on credential"] });
return;
case "nothingSelected":
res.status(400).json({ errors: ["Nothing selected"] });
return;
case "cryptosuiteMismatch":
res.status(400).json({ errors: ["cryptosuite not appropriate for endpoint"]});
return;
case "verifyError":
case "verifyBaseError":
case "deriveError":
res.status(400).json({ errors: [err.message] });
return;
default:
res.status(500).json({ errors: ["Unknown"] });
return;
}
}