feat(errors): parse sequelize errors and use the relevant Boom error type
This commit is contained in:
parent
b18479e02e
commit
17105f66f4
22
src/error.js
22
src/error.js
@ -1,4 +1,8 @@
|
|||||||
|
<<<<<<< b18479e02e3d47da4e40369a8132e07125eb96a3
|
||||||
import Boom from 'boom';
|
import Boom from 'boom';
|
||||||
|
=======
|
||||||
|
import { wrap } from 'boom';
|
||||||
|
>>>>>>> whatever
|
||||||
|
|
||||||
export default (target, key, descriptor) => {
|
export default (target, key, descriptor) => {
|
||||||
const fn = descriptor.value;
|
const fn = descriptor.value;
|
||||||
@ -7,6 +11,7 @@ export default (target, key, descriptor) => {
|
|||||||
try {
|
try {
|
||||||
await fn(request, reply);
|
await fn(request, reply);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
<<<<<<< b18479e02e3d47da4e40369a8132e07125eb96a3
|
||||||
if (e.original) {
|
if (e.original) {
|
||||||
const { code, detail } = e.original;
|
const { code, detail } = e.original;
|
||||||
|
|
||||||
@ -45,6 +50,23 @@ export default (target, key, descriptor) => {
|
|||||||
reply(err);
|
reply(err);
|
||||||
} else {
|
} else {
|
||||||
reply(e);
|
reply(e);
|
||||||
|
=======
|
||||||
|
const { code, detail } = e.original;
|
||||||
|
|
||||||
|
// pg error codes https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
|
||||||
|
if (code && (code.startsWith('22') || code.startsWith('23'))) {
|
||||||
|
const error = wrap(e, 406);
|
||||||
|
|
||||||
|
// detail tends to be more specific information. So, if we have it, use.
|
||||||
|
if (detail) {
|
||||||
|
error.message += `: ${detail}`;
|
||||||
|
error.reformat();
|
||||||
|
}
|
||||||
|
|
||||||
|
reply(error);
|
||||||
|
} else {
|
||||||
|
reply(wrap(e));
|
||||||
|
>>>>>>> whatever
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user