REST error handling
REST errors returned by the endpoints in an app are often too technical for end-users to comprehend. Jigx allows you to customize these error messages to improve user experience, communicate more effectively, and ensure users understand that errors are not their fault. By configuring custom error handling, you can:
Suppress or customize default error messages. See Configuring error alerts.
Log error details for more effective debugging. See Error logging and debugging.
Create more robust and user-friendly error solutions. See Working with commandQueue.
Key features
Custom error messages: Control the message shown to users when a REST error occurs.
User-friendly retry options: Allow users to retry an action when an error occurs.
By default, Jigx automatically catches any 429 error responses and retries the request up to three times, with a five-second delay between each attempt.
By default, Jigx automatically catches any 401 error responses and retries the request up to three times.
Error logging: Automatically log error details for debugging.
Dynamic responses: Build logic to respond to specific errors flexibly.


Common Error Scenarios
Network failures
Authentication/authorization errors
Rate limiting
Server errors vs client errors
How does it work
In Jigx, REST error handling is configured through an error section in the REST function. This allows the system to catch various error responses and act accordingly:
Multiple error responses can be defined and are evaluated in sequence.
Error responses can trigger notifications, log errors, or provide retry options for users.
The app supports customized alert messaging as a toast or modal for each error type.
Expressions are supported in functions.
High level steps
Before diving into details, here's what you need:
Configure the
errorsection in the REST functionDefine error conditions with
whenCreate a datasource for the error table.
Configure user alerts and/or logging
(Optional) - Create a UI (jig) for error management, to process the errors in the queue using the commandQueue actions.
Considerations
By default, Jigx automatically handles
429(Too Many Requests) error responses for CRUD and sync methods by retrying the request up to three times, with a five-second delay between each attempt. If the request still fails after the third retry, the error is raised in the app. You can customize this behavior by configuring the handling of the 429 status in theerrorproperty.When configuring error handling with
alerts, ensure that HTTP 200 (success) responses are excluded. If not, the app may treat successful responses as errors, preventing data from loading.Errors are automatically grouped by default to prevent alert overload, unless a custom error handler is explicitly configured.
REST Function
In the Jigx function file, configure the error section to cater for:
Customizing the error message.
Determining if a toast or modal alert notification is required or not.
Group related alerts to prevent multiple alerts from stacking one after another.
Writing the context of the error to a table for debugging and configuring actions to fix the error.
Multiple error handlers can be added in the function, which are executed from the top to bottom until one matches. The error section needs to be configured in each of the individual REST function files.

Configuration properties
The following properties are available for configuration when handling REST errors:
alert
description
Description of the error for logging purposes.
Provide a detailed message of the error to write to the logs. Defaults to the provider's description if absent. For example, the REST provider uses the HTTP status code and message. The description property supports localization.
details
Add additional error details for logging purposes. Defaults to the provider's details if absent.
notification
Determines whether the error alert message notification should be shown on the device. (true/false)
operations
Additional table operations for the error table. See Operations for more details.
Specify none or more conditional table operations/transforms.
Each operation is evaluated in the order specified, if the
whencondition is met it is executed.If a table is not specified, the default table will be used ("{entity}_error").
If the same table is specified multiple times, then each operation will be executed in order.
table: Define a table where the error information specified in thetransformproperty will be logged to, for example:table: =@ctx.entity & "_error"records: Specifies the details to log in the table for the error, such as the request, response, and user context, for example:'={ "id": @ctx.commandId, "type": "System Offline", "response": @ctx.response, "request": @ctx.request, "user": @ctx.user, "solution": @ctx.solution, "entity": @ctx.entity, "correlationId": @ctx.correlationId}'
retry
Provides the ability to configure an automatic retry, set a delay time before the retry is executed, and specify the maximum number of retries allowed. By default, Jigx automatically handles 429 (Too Many Requests) error responses for CRUD and sync methods by retrying the request up to three times, with a five-second delay between each attempt. If the request still fails after the third retry, the error is raised in the app. You can customize this behavior by configuring the handling of the 429 status in the error property.
title
Title of the error for logging purposes. Defaults to the provider's title if not provided. The title property supports localization.
when
Checks if the result of the function is an error, the first one that resolves to true is used.
The REST provider uses a combination of actual errors encountered and the HTTP status code and message.
Configure different types of actions depending on the error received, by using multiple
whenstatements.If the property is not configured it defaults to the REST provider's default error check.
Basic configuration example
Configuring OAuth error messages
When
useLocalCall: trueis set, functions that rely on secrets or other authentication mechanisms not available locally will not execute.For full details on configuring OAuth error messages, see Configuring OAuth error messages.
Examples and code snippets
See REST error example to understand how to configure error responses in a REST function, create a error table and use the commandQueue with actions to process the error.
See Configuring OAuth error messages for an example of customizing OAuth error messages.
Last updated
Was this helpful?