I am getting an error message(404) in text/html format
Can I handle that html message in a RaiseFault Policy?
What I mean is: can I access a specific fields or tag-elements in the html error message?
Solved! Go to Solution.
If you are getting this in response.content but not getting a 404 result code then we need to talk to your target system API provider!
In all seriousness though, you can use a Javascript policy to regex or otherwise examine the body of the response and from there set variables, set the response code, or do whatever action you need to trigger the right response - something like the following:
function process(body) { if (body === "") { //handle malformed response from target on 404 context.setVariable("response.status.code", 404); return ""; } else { try { var payload = payloadMediator(JSON.parse(body)); return JSON.stringify(payload); } catch (e) { context.setVariable("logError", JSON.stringify({ error: e.message, detail: e.stack })); throw (e); } } }