Fix a bug in error parsing #21
34
src/error.js
34
src/error.js
@ -8,20 +8,34 @@ export default (target, key, descriptor) => {
|
|||||||
await fn(request, reply);
|
await fn(request, reply);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.original) {
|
if (e.original) {
|
||||||
const { code, detail } = e.original;
|
const { code, detail, hint } = e.original;
|
||||||
|
let error;
|
||||||
|
|
||||||
// pg error codes https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
|
// pg error codes https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
|
||||||
if (code && (code.startsWith('22') || code.startsWith('23'))) {
|
if (code && (code.startsWith('22') || code.startsWith('23'))) {
|
||||||
const error = Boom.wrap(e, 406);
|
error = Boom.wrap(e, 406);
|
||||||
|
} else if (code && (code.startsWith('42'))) {
|
||||||
// detail tends to be more specific information. So, if we have it, use.
|
error = Boom.wrap(e, 422);
|
||||||
if (detail) {
|
// TODO: we could get better at parse postgres error codes
|
||||||
error.message += `: ${detail}`;
|
} else {
|
||||||
error.reformat();
|
// use a 502 error code since the issue is upstream with postgres, not
|
||||||
}
|
// this server
|
||||||
|
error = Boom.wrap(e, 502);
|
||||||
reply(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// detail tends to be more specific information. So, if we have it, use.
|
||||||
|
if (detail) {
|
||||||
|
error.message += `: ${detail}`;
|
||||||
|
error.reformat();
|
||||||
|
}
|
||||||
|
|
||||||
|
// hint might provide useful information about how to fix the problem
|
||||||
|
if (hint) {
|
||||||
|
error.message += ` Hint: ${hint}`;
|
||||||
|
error.reformat();
|
||||||
|
}
|
||||||
|
|
||||||
|
reply(error);
|
||||||
} else if (!e.isBoom) {
|
} else if (!e.isBoom) {
|
||||||
const { message } = e;
|
const { message } = e;
|
||||||
let err;
|
let err;
|
||||||
|
Loading…
Reference in New Issue
Block a user