Skip to content

Commit

Permalink
Handle response errors [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Oct 12, 2018
1 parent 362bc1a commit 24a8ecc
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const soap = require('soap');
const MarketingCloudAuth = require('marketing-cloud-auth');
const applyAuthHeader = require('./utils/apply-auth-header');
const ResponseError = require('./objects/response-error');

class MarkingCloudSOAP {
/**
Expand Down Expand Up @@ -30,15 +31,15 @@ class MarkingCloudSOAP {
* @param {string} type
* @param {string[]} [props]
*/
async retrieve(type, props) {
async retrieve(type, props = ['CustomerKey']) {
const client = await this.client();
const [result] = await client.RetrieveAsync({
const [result, rawResponse, rawRequest] = await client.RetrieveAsync({
RetrieveRequest: {
ObjectType: type,
Properties: props,
},
});
return result;
return this.handleResponse({ result, rawResponse, rawRequest });
}

/**
Expand Down Expand Up @@ -71,6 +72,21 @@ class MarkingCloudSOAP {
throw e;
}
}

/**
* @private
* @param {object} params
*/
handleResponse({ result, rawResponse, rawRequest } = {}) {
if (result && result.OverallStatus && result.OverallStatus !== 'OK') {
throw new ResponseError({
result,
rawResponse,
rawRequest
}, result.OverallStatus);
}
return result;
}
}

module.exports = MarkingCloudSOAP;

0 comments on commit 24a8ecc

Please sign in to comment.