From ce30b1090674fdb83cbb02a7cf1f5728c12b05b3 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Fri, 14 Aug 2015 18:25:33 -0700 Subject: [PATCH] Attach the original Postgres error to unique errors Currently it gets clobbered, which makes it difficult to determine which uniqueness constraint failed. This way, you can always check err.originalError to get the original node-postgres error message, with information about the constraint, PG error code and table that failed. --- lib/adapter.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/adapter.js b/lib/adapter.js index 66a41bd9..26eba2dd 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -1232,6 +1232,9 @@ module.exports = (function() { if (matches && matches.length) { formattedErr = {}; formattedErr.code = 'E_UNIQUE'; + // This is the same property that is set on WLError instances. + // Accessible as `.originalError` on a WLValidationError instance. + formattedErr.originalError = err; formattedErr.invalidAttributes = {}; formattedErr.invalidAttributes[matches[1]] = [{ value: matches[2],