From 7d7894c64d304e3e1745b8234d5a6027f976698c Mon Sep 17 00:00:00 2001 From: Adam Jaffe Date: Wed, 9 May 2018 16:19:43 -0400 Subject: [PATCH] Change format of callback argument --- src/core.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/core.js b/src/core.js index 7b15723..3a2a16f 100644 --- a/src/core.js +++ b/src/core.js @@ -175,7 +175,10 @@ module.exports = ( try { json = JSON.parse(result); } catch (e) { - callback(status); + callback({ + status, + error: e, + }); return; } @@ -183,7 +186,10 @@ module.exports = ( if (!meta) { logger.error(`Response had no metadata: ${util.inspect(json)}`); - callback(new Error(`Response had no metadata: ${util.inspect(json)}`)); + callback({ + status, + error: new Error(`Response had no metadata: ${util.inspect(json)}`), + }); return; } @@ -191,14 +197,20 @@ module.exports = ( if (!code) { logger.error(`Response had no code: ${util.inspect(json)}`); - callback(new Error(`Response had no code: ${util.inspect(json)}`)); + callback({ + status, + error: new Error(`Response had no code: ${util.inspect(json)}`), + }); return; } else if (code !== 200) { logger.error( `JSON Response had unexpected code: '${code}: ${errorDetail}'`, ); - callback(new Error(`${code}: ${errorDetail}`)); + callback({ + status, + error: new Error(`${code}: ${errorDetail}`), + }); return; } @@ -213,7 +225,10 @@ module.exports = ( if (config.foursquare.warnings === 'ERROR') { logger.error(message); - callback(new Error(message)); + callback({ + status, + error: new Error(message), + }); return; }