For the complete documentation index, see llms.txt. This page is also available as Markdown.

REST errors

Scenario

When trying to view a customer and their details or create a new customer in the app, the app can fail to retrieve or create the required data, and various errors are returned. In this example, we add error handling to the REST endpoint functions to cater for the following errors:

  • 401 Unauthorized

  • 403 Forbidden

  • Unexpected error

REST Error handling
Error REST handling

How does this work

An error section is added to the REST endpoint functions for creating customers (POST), viewing customers (GET), and updating customers (PUT). In this section, the when property is configured with an expression that returns the response status from the endpoint, for example, =@ctx.response.status = 403. There are multiple when properties configured to catch a 401 and 403 error; all other response statuses are caught in the Unexpected error. Each when property has:

  • An alert notification message configured which is displayed either as a toast or modal to the user in the app.

  • An operation which writes the details to the customers_error table for logging and debugging purposes, which provides an explanation of the error. The data written to the table is configured in the records property. The table in conjunction with the commandQueue is used to troubleshoot the error and create jigs that allows you to retry the REST call or delete the error from the commandQueue. See REST error handling for more information.

Consideration

  • Use groupId to manage multiple alerts for the same issue. When using modal presentation, alerts with the same groupId are grouped so that only the first alert appears and subsequent ones are automatically skipped. When using toast presentation, alerts are also grouped, preventing duplicates. Users can tap the toast to view details, if multiple alerts exist, they stack and display a count at the top. Swiping left lets users view each alert’s details within the stack.

  • 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.

REST API

REST
Detail

URL

https://[your_rest_service]/api/customers

Operation/Method

POST,GET,PUT

Function

In each of the REST function files (GET, POST, PUT), add an error section with alerts and configure the YAML to cater for a 401 and 403 error, and a section to cater for all other response errors.

Datasources

Add a file under the datasource folder to configure the local data provider with the data returned from the customers_error table. This data is used to provide detail of the error in a jig and to configure actions allowing the item to be retried or deleted.

Error Center - Jigs (screens)

There are a number of options available to process items that are in an error state.

  1. Use the commandQueue. Items that return an error from the REST endpoint will remain on the commandQueue and are not automatically processed by the queue. You must configure an action to either retry the item or delete the item from the queue. The retry executes the REST call again.

  2. Use the customers_error table configured in the function. Use the data from the table in a jig to allow app users to resolve the error or delete the item in error.

  3. Add a banner component to the home screen with a when condition that displays when errors exist in the customers_error table. Add an action to go-to the issues (error center) list.

Error center
Error Center

Add a banner to the customer list

Add a banner component with a when condition that displays when errors exist in the customers_error table. Use an expression with $count in the banner title to show the number of errors. Include a go-to action that navigates to the list of issues and errors. Configure the list to display the error type, statusText, and status.

Enable Retry and Delete swipe actions. When deleting an error, ensure the delete action removes the record from both the commandQueue and the customers_error table.

Use the commandQueue

Create a jig to work with the items in the commandQueue. This is helpful for the solution owner or administrator to take action and delete errors in the queue or possibly retry the REST call to process the items in the queue that are in an error state. Configure a list jig containing all items in the commandQueue, add a left swipeable action to cater for the delete and retry actions.

Use the customers_error table

Create a list jig to list the records in the customers_error table.

  • Provide detail of the error in the title and subtitle properties.

  • Add a swipeable event and configure a retry-queue-command action, and two execute-entity actions to delete the records from the commandQueue and the customers_error tables.

  • Similarly, add actions to the list that retry or delete all errors in the list. The execute-entities action is used with specific expressions that include multiple records:

    • =@ctx.datasources.command-queue.id - retries multiple items in the CommandQueue at the same time.

    • =@ctx.datasources.customers-errors.{"id":id}[] - deletes all records in the customers_error table.

Index

For performance and offline support the data is synced from the REST service as soon as the app is opened or receives focus. This is achieved by calling the global action in the onFocus events.

See Also

Last updated

Was this helpful?