Skip to content

Commit

Permalink
[SDK-1405] Added support for new 'blocked_reasons' error type (#1084)
Browse files Browse the repository at this point in the history
* Added support for new 'blocked_reasons' error type

* Made error codes + details more generic

* Removed check for `blocked_users` code
* Changed property name on error object from `blockUser` to
`errorDetails`
  • Loading branch information
Steve Hobbs authored Mar 27, 2020
1 parent b7327d6 commit a7e55bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
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

0 comments on commit a7e55bf

Please sign in to comment.