From a7e55bf326f4f0cb5858e0f5df504040f8d01566 Mon Sep 17 00:00:00 2001 From: Steve Hobbs Date: Fri, 27 Mar 2020 12:34:49 +0000 Subject: [PATCH] [SDK-1405] Added support for new 'blocked_reasons' error type (#1084) * 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` --- src/helper/response-handler.js | 9 ++++++ test/helper/response-handler.test.js | 41 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/helper/response-handler.js b/src/helper/response-handler.js index 21c76743..15e754c3 100644 --- a/src/helper/response-handler.js +++ b/src/helper/response-handler.js @@ -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 || @@ -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; } diff --git a/test/helper/response-handler.test.js b/test/helper/response-handler.test.js index 34e9d86f..499510ee 100644 --- a/test/helper/response-handler.test.js +++ b/test/helper/response-handler.test.js @@ -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: {