From da6b3ce963b6c7d8983593d5940d6535ce0fb3c9 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Sun, 4 Sep 2016 17:26:51 -0700 Subject: [PATCH] Feat (error) include `hint` on PG errors Provides useful info! --- src/error.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/error.js b/src/error.js index a9d0510..54fdc7e 100644 --- a/src/error.js +++ b/src/error.js @@ -8,7 +8,8 @@ export default (target, key, descriptor) => { await fn(request, reply); } catch (e) { 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 if (code && (code.startsWith('22') || code.startsWith('23'))) { @@ -20,6 +21,10 @@ export default (target, key, descriptor) => { error.reformat(); } + // hint might provide useful information about how to fix the problem + if (hint) { + error.message += ` Hint: ${hint}`; + error.reformat(); } reply(error);