Error handling
It is important to implement error handling in your app so your users clearly understand the cause of the error.
Each service sends an error message when an error occurs. This usually happens when the request has wrong parameters or values or when the service has an outage.
When an error occurs, the module should indicate the error as well as a detailed message that can then be used in filters. The message should be clear and user-friendly. For example, instead of "Error: contact_not_found", your message should be "[404] The specified contact was not found."
The error handling code should correspond to the structure of the server response.
Error handling example
In this example, the JSON response has the following format in cases where something goes wrong:
{
"error": {
"code": "E101",
"message": "The company with the given ID does not exist."
}
}
Here's how the error section should (and should not) look:
"response": {
"error": {
"message": "[{{statusCode}}] {{body.error.message}} (error code: {{body.error.code}})"
}
}
Common error messages
4xx: Client Error
4xx errors indicate something wrong on the client side.
5xx: Server Error
5xx errors indicate something wrong on the side of the third-party service.
Handling status code 200
Sometimes the API returns status code 200 with an error in the body. For this situation, use the Valid directive, which tells whether the response should be processed or an error should be thrown.
Sometimes the API returns status code 200 without errors to an incorrect request. This can happen, for example, if the Get a/an [item] module is developed based on the Search endpoint and not based on a separate endpoint. This may be the case if a separate endpoint for that action is not implemented on the service’s side.
Incorrect example of the Search approach for a Get module:
{
"url": "/items",
"method": "GET",
"qs": {
"id": "{{parameters.itemId}}"
},
"response": {
"output": "{{body.items[1]}}"
}
}
Last updated