Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-1405] Added support for new generic error details #1084

Merged
merged 4 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/helper/response-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function wrapCallback(cb, options) {

errObj.code =
err.code || err.error || err.error_code || err.status || null;

errObj.description =
err.errorDescription ||
err.error_description ||
Expand All @@ -53,11 +54,19 @@ function wrapCallback(cb, options) {
err.details ||
err.err ||
null;

if (options.forceLegacyError) {
errObj.error = errObj.code;
errObj.error_description = errObj.description;
}

if (err.error_codes && err.error_details) {
errObj.errorDetails = {
codes: err.error_codes,
details: err.error_details
};
}

if (err.name) {
errObj.name = err.name;
}
Expand Down
41 changes: 41 additions & 0 deletions test/helper/response-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ describe('helpers responseHandler', function() {
})(assert_err, null);
});

it('should return normalized error codes and details', function(done) {
var assert_err = {};
assert_err.response = {};
assert_err.response.body = {
code: 'blocked_user',
error: 'Blocked user.',
error_codes: ['reason-1', 'reason-2'],
error_details: {
'reason-1': {
timestamp: 123
},
'reason-2': {
timestamp: 456
}
}
};

responseHandler(function(err, data) {
expect(data).to.be(undefined);

expect(err).to.eql({
original: assert_err,
code: 'blocked_user',
description: 'Blocked user.',
errorDetails: {
codes: ['reason-1', 'reason-2'],
details: {
'reason-1': {
timestamp: 123
},
'reason-2': {
timestamp: 456
}
}
}
});

done();
})(assert_err, null);
});

it('should return the data', function(done) {
var assert_data = {
body: {
Expand Down