Skip to content

Commit

Permalink
Change format of callback argument
Browse files Browse the repository at this point in the history
  • Loading branch information
adamJaffe2 committed May 9, 2018
1 parent 0f122f7 commit 7d7894c
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,42 @@ module.exports = (
try {
json = JSON.parse(result);
} catch (e) {
callback(status);
callback({
status,
error: e,
});
return;
}

const {meta, response} = json;

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;
}

const {code, errorDetail, errorType} = meta;

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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 7d7894c

Please sign in to comment.