I have an API that returns different error structures for different endpoints and status codes. Sometimes it's a string, sometimes a complex object or an array. Since Integromat requires all error handling to be done in one place in the Base and not in the modules, how can I implement this correctly? Case 1
"data": {
"error": {
"user_ids.0": [
"The user_ids.0 must be an integer."
]
}
}
Case 2
"data": {
"error": "Not found"
}
It is possible to use the JavaScript function for processing the response and getting an error message. Please take a look at the example below:
Base:
{
"response": {
"output": "...",
"error": "{{parseErrorMessage(body)}}"
}
}
function parseErrorMessage(body) {
if ('string' === typeof body.data) return body.data;
...
}
Custom JS is disabled by default, please get in touch with our support to enable it. Ref: https://docs.integromat.com/apps/app-structure/iml-functions