Use the Error Handling section to define custom logic for extracting and displaying meaningful messages from failed HTTP responses.
Purpose
The Error Message Function enables you to interpret and return appropriate error messages based on the HTTP response from an external API. This function is evaluated automatically whenever an API call fails, allowing you to present users with more specific, helpful feedback.
Default Error Handling Behavior
Below is the default logic used in the Error Message Function:
// Add custom transformation hereif (http.code>=200&&http.code<400) { // No error if success codereturnnull;}elseif (data['message']) { // Display error message if available in responsereturndata['message'];}else{ // Generic error if no message foundreturntrue;}
Explanation:
http.code >= 200 && http.code < 400
If the HTTP response code indicates success (2xx or 3xx), no error is returned.
data['message']
If the response contains a message field (e.g., { "message": "Invalid credentials" }), it will be displayed as the error message.
return true
If no specific message is found, a generic error is triggered.
Custom Error Handling Examples
You can extend this function to handle specific status codes or error formats depending on your API’s behavior.
Example 1: Handle Unauthorized Access (HTTP 401) with Default Fallback
Example 2: Handle Rate Limiting (HTTP 429) and Fallback to Default