This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Call callback even if there is exception #135
Open
syuraj
wants to merge
1
commit into
salesforce-marketingcloud:master
Choose a base branch
from
syuraj:callback-even-if-error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -555,67 +555,72 @@ FuelSoap.prototype._parseResponse = function(key, body, callback) { | |
}; | ||
|
||
parseString(body, parseOptions, function(err, res) { | ||
if(err) { | ||
err.errorPropagatedFrom = 'xml2js.parseString'; | ||
callback(err, null); | ||
return; | ||
} | ||
try{ | ||
if(err) { | ||
err.errorPropagatedFrom = 'xml2js.parseString'; | ||
callback(err, null); | ||
return; | ||
} | ||
|
||
var soapError; | ||
var soapBody = res['soap:Envelope']['soap:Body']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was getting exception from here when |
||
|
||
var soapError; | ||
var soapBody = res['soap:Envelope']['soap:Body']; | ||
// Check for SOAP Fault | ||
if(soapBody['soap:Fault']) { | ||
var fault = soapBody['soap:Fault']; | ||
soapError = new Error(fault.faultstring); | ||
soapError.faultstring = fault.faultstring; | ||
soapError.faultCode = fault.faultcode; | ||
|
||
// Check for SOAP Fault | ||
if(soapBody['soap:Fault']) { | ||
var fault = soapBody['soap:Fault']; | ||
soapError = new Error(fault.faultstring); | ||
soapError.faultstring = fault.faultstring; | ||
soapError.faultCode = fault.faultcode; | ||
if(fault.detail) { | ||
soapError.detail = fault.detail; | ||
} | ||
|
||
if(fault.detail) { | ||
soapError.detail = fault.detail; | ||
soapError.errorPropagatedFrom = 'SOAP Fault'; | ||
callback(soapError, null); | ||
return; | ||
} | ||
|
||
soapError.errorPropagatedFrom = 'SOAP Fault'; | ||
callback(soapError, null); | ||
return; | ||
} | ||
var parsedRes = soapBody[key]; | ||
|
||
var parsedRes = soapBody[key]; | ||
if(key === 'DefinitionResponseMsg') { | ||
// Return empty object if no ObjectDefinition is returned. | ||
parsedRes.ObjectDefinition = parsedRes.ObjectDefinition || {}; | ||
callback(null, parsedRes); | ||
return; | ||
} | ||
|
||
if(key === 'DefinitionResponseMsg') { | ||
// Return empty object if no ObjectDefinition is returned. | ||
parsedRes.ObjectDefinition = parsedRes.ObjectDefinition || {}; | ||
callback(null, parsedRes); | ||
return; | ||
} | ||
// Results should always be an array | ||
parsedRes.Results = Array.isArray(parsedRes.Results) ? parsedRes.Results : isObject(parsedRes.Results) ? [parsedRes.Results] : []; | ||
|
||
// Results should always be an array | ||
parsedRes.Results = Array.isArray(parsedRes.Results) ? parsedRes.Results : isObject(parsedRes.Results) ? [parsedRes.Results] : []; | ||
if(key === 'RetrieveResponseMsg') { | ||
if(parsedRes.OverallStatus === 'OK' || parsedRes.OverallStatus === 'MoreDataAvailable') { | ||
callback(null, parsedRes); | ||
} else { | ||
// This is an error | ||
soapError = new Error(parsedRes.OverallStatus.split(':')[1].trim()); | ||
soapError.requestId = parsedRes.RequestID; | ||
soapError.errorPropagatedFrom = 'Retrieve Response'; | ||
callback(soapError, null); | ||
} | ||
return; | ||
} | ||
|
||
if(key === 'RetrieveResponseMsg') { | ||
if(parsedRes.OverallStatus === 'OK' || parsedRes.OverallStatus === 'MoreDataAvailable') { | ||
callback(null, parsedRes); | ||
} else { | ||
// This is an error | ||
soapError = new Error(parsedRes.OverallStatus.split(':')[1].trim()); | ||
if(parsedRes.OverallStatus === 'Error' || parsedRes.OverallStatus === 'Has Errors') { | ||
soapError = new Error('Soap Error'); | ||
soapError.requestId = parsedRes.RequestID; | ||
soapError.errorPropagatedFrom = 'Retrieve Response'; | ||
soapError.results = parsedRes.Results; | ||
soapError.errorPropagatedFrom = key; | ||
callback(soapError, null); | ||
return; | ||
} | ||
return; | ||
} | ||
|
||
if(parsedRes.OverallStatus === 'Error' || parsedRes.OverallStatus === 'Has Errors') { | ||
soapError = new Error('Soap Error'); | ||
soapError.requestId = parsedRes.RequestID; | ||
soapError.results = parsedRes.Results; | ||
soapError.errorPropagatedFrom = key; | ||
callback(soapError, null); | ||
return; | ||
} | ||
|
||
callback(null, parsedRes); | ||
callback(null, parsedRes); | ||
} catch(error){ | ||
callback(err, null); | ||
} | ||
}.bind(this)); | ||
|
||
}; | ||
|
||
// Methods that need implementations | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try
,catch
is the only change in this pr