How can I map SOAP Fault to REST JSON object in API Connect?
I am handling SOAP Faults by check "Stop on Error" in my Invoke component, however, I don´t know how to get fault body and set in a JSON object in my message.body, for instance
I found out how to solve this issue.
In my case, my problem was that the invoke´s variable output exposed me its JSON body as a NodeList XML, so I couldn´t retrieve any information of this.
I got this variable and transformed it to XML in a gatewayscript
var nodeList = apim.getvariable('<responseServiceVariable>.body');
apim.setvariable('message.headers.content-type', 'application/xml')
apim.setvariable('message.body', nodeList);
After that, I used the XML-to-JSON component.
And then, I transformed response with other gatewayscript
apim.readInputAsJSON(function (error, json) {
if (error) {}
var jsonString = JSON.stringify(json)
.replace(/\$/g,'value');
var jsonReplaced = JSON.parse(jsonString);
var envelope = jsonReplaced['s:Envelope'];
var body = envelope['s:Body'];
var fault = body['s:Fault'];
var faultstring = fault['faultstring'];
var moreInformation = faultstring['value'];
var httpMessage = "My httpMessage"
var error = {"httpCode": 400, "httpMessage": httpMessage, "moreInformation": moreInformation}
apim.setvariable('message.headers.content-type', 'application/json')
apim.setvariable('message.status.code', 400);
apim.setvariable('message.body', error);
});