From b032be20d129be51a7b5d3b0a380f0c8ef0c287b Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Sun, 4 Sep 2016 17:25:57 -0700 Subject: [PATCH 1/3] Fix (error) always reply with an error #oops We had a case where reply would never be called. This could case a server hang. --- src/error.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/error.js b/src/error.js index af49e86..a9d0510 100644 --- a/src/error.js +++ b/src/error.js @@ -14,14 +14,15 @@ export default (target, key, descriptor) => { if (code && (code.startsWith('22') || code.startsWith('23'))) { const error = Boom.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); + // detail tends to be more specific information. So, if we have it, use. + if (detail) { + error.message += `: ${detail}`; + error.reformat(); } + + } + + reply(error); } else if (!e.isBoom) { const { message } = e; let err; From da6b3ce963b6c7d8983593d5940d6535ce0fb3c9 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Sun, 4 Sep 2016 17:26:51 -0700 Subject: [PATCH 2/3] 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); From bab2e90cbbf77e01093468a76d54f0dc5d31808f Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Sun, 4 Sep 2016 17:27:07 -0700 Subject: [PATCH 3/3] Feat (error) parse PG 42* errors --- src/error.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/error.js b/src/error.js index 54fdc7e..3bb7384 100644 --- a/src/error.js +++ b/src/error.js @@ -13,7 +13,15 @@ export default (target, key, descriptor) => { // pg error codes https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html 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'))) { + error = Boom.wrap(e, 422); + // TODO: we could get better at parse postgres error codes + } else { + // use a 502 error code since the issue is upstream with postgres, not + // this server + error = Boom.wrap(e, 502); + } // detail tends to be more specific information. So, if we have it, use. if (detail) {