What is your goal?
Handle 4xx and 5xx errors in my custom app.
In case of 2xx the result should be parsed e.g. documentId from response body.id.
What is the problem?
In case of 2xx the API returns application/json and that works fine.
But in case of an error (4xx/5xx) the return is just text/plain, and in this case i get an error.
e.g. REST Body (Status 403): “No entity found by given predicate”
error message: The operation failed with an error. Body is not a valid JSON. Unexpected token ‘N’, "No entity "… is not valid JSON
It should only try to parse JSON in case of 2xx
What have you tried so far?
I tried to add handling like this, but then i get an error, that the response could not be parsed as a json.
{
"url": "{{connection.baseUrl}}/documents/{{parameters.documentId}}",
"headers": {
"Authorization": "Bearer {{parameters.instanceToken}}"
},
"type": "json",
"method": "DELETE",
"response": {
"error": {
"message": "[{{statusCode}}] {{error.output}}"
},
"output": {
"documentId": "{{body.id}}",
"headers": "{{headers}}",
"statusCode": "{{statusCode}}"
}
}
}