---
schema_version: "1"
id: 08c9dda42e8caf1dcb27d363404fd3c2834af8103dc634b1800154870600ce22
title: Error Handling for Asynchronous Components
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/bots_service_enhanced_async_errors.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.bots_service_enhanced_async_errors.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 97080ad3f74b11d7dc4922268a164d47e95a9d7a9ef5dee7cdc6b84c00cc7b4b
description: Asynchronous components include an optional error variable to give you more control over how to handle specific errors. Use an Apex class and Rule actions to customize the behavior of the Error Handler dialog based on the error variable. For example, when a customer attempts to respond to an expired authentication request, you can prompt the user to try again with a new authentication request.
products:
  - Service Cloud
  - Service Intelligence
release: "264"
---
# Error Handling for Asynchronous Components

Asynchronous components include an optional error variable to give you more control over how to handle specific errors. Use an Apex class and Rule actions to customize the behavior of the Error Handler dialog based on the error variable. For example, when a customer attempts to respond to an expired authentication request, you can prompt the user to try again with a new authentication request.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=service.einstein_service_intro.htm&amp;language=en_US" target="_blank">View supported editions</a> for Einstein Bots.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=service.messaging_editions.htm&amp;language=en_US" target="_blank">View supported editions</a> for Messaging.</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d54316e67">User Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d54316e67 ">To build and manage Einstein Bots:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d54316e67 ">
              <p>Customize Application</p>
              <p>OR</p>
              <p>Modify Metadata</p>
              <p>OR</p>
              <p style="margin-bottom:0;">Manage Bots</p>
            </td>

          </tr>
        </tbody>
      </table>

Unlike other messaging components in Einstein Bots, asynchronous components don’t include conversation repair attempts. Instead, these components redirect to the system Error Handler dialog. Without any customization, the Error Handler dialog delivers a message and redirects the customer to the Main Menu dialog. Starting over makes sense when the customer encounters certain errors, such as an internal server error. But it’s not very efficient for the customer or the bot when the error is recoverable, such as a component timeout or an invalid shipping address.

When you add an asynchronous component to your bot, you’re prompted to specify an object list variable to store any error codes or types triggered by customer interaction with the component.

![Error Handling section of Step Properties panel](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_intelligence-264-0-0-production-enus/dcd06a7b-b5ab-448b-a767-4e2e90481508/support_intelligence/images/bots/bots_error_variable.png)

You can use the variable with an Apex class to customize the behavior of the Error Handler dialog.

1. From the Apex Classes page in Setup, create an Apex class that loops through the list of errors stored in the object list variable and returns the error codes or types.
    
    For example:
    
    ```
    public with sharing class CheckBotError {
      @InvocableMethod(label='CheckBotError')
      public static List<String> CheckBotError(List<chatbots.Error> errors) {
        List<String> returnVal = new List<String>();
        
          for (chatbots.Error err : errors) {
               if (err.errorType == 'TEST_TYPE') {
                   returnVal.add('There was an issue with FOO. Please try SOMETHING ELSE.');
               }
          }
          
        return returnVal;
      }
    }
    ```
2. Add the Apex class to your bot’s Error Handler dialog to make the error codes and types available to your bot.
    1. Go to the Bot Builder. Click **Dialogs**, and then select the Error Handler system dialog or any other dialog you use for error handling.
    2. From the Dialog Component Library, drag the **Apex** action dialog step onto the canvas.
    3. In the Step Properties panel, select the Apex class you created.
    4. For the input, select the object list variable you use to store the errors from your asynchronous component.
    5. For the output, create or select a variable to store the error codes or types the Apex class returns. Choose the variable type that works best with your Apex class and business case.
3. [Add Rule steps](https://help.salesforce.com/s/articleView?id=service.bots_service_setup_dialog_rule.htm&release=264.0.0&type=5 "Use rules to specify the conditions that start any of these actions: call a dialog from within the current dialog, redirect to a different dialog, clear a variable value, transfer to a service rep, and set a variable. Use rules to send targeted messages to your customers with Conditional Messaging. Rule conditions are optional.") to customize the behavior of the Error Handler dialog. For every error code or type that you want to handle, create a condition that triggers the Rule step when the variable you specified in your Apex class contains the error code or type.
4. Save your changes.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:33.33333333333333%">
          <col style="width:66.66666666666666%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:left;vertical-align:top;" id="d54316e206">Available Error Codes and Types</th>
          </tr>
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" id="d54316e212">Component</th>
            <th scope="col" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" id="d54316e215">Error Codes and Types</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Component" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" headers="d54316e206 d54316e212 ">Authentication</td>

            <td data-label="Error Codes and Types" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" headers="d54316e206 d54316e215 ">
              <ul>
                <li>InvalidAuthenticationRequest</li>

                <li>AccessDenied</li>

                <li>InvalidScope</li>

                <li>AuthenticationRequestExpired</li>

                <li>InternalServerError </li>

                <li>TemporarilyUnavailable</li>

              </ul>
            </td>

          </tr>
          <tr class="">
            <td data-label="Component" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" headers="d54316e206 d54316e212 ">Form</td>

            <td data-label="Error Codes and Types" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" headers="d54316e206 d54316e215 ">
              <ul>
                <li>InvalidFormResponse</li>

                <li>FormRequestExpired</li>

                <li>ApiResultErrorCode: When this is the error type, then the errorCode field will
                  contain a Salesforce error code.</li>

                <li>InternalServerError</li>

              </ul>
            </td>

          </tr>
          <tr class="">
            <td data-label="Component" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" headers="d54316e206 d54316e212 ">Payment</td>

            <td data-label="Error Codes and Types" class="slds-cell-wrap" style="text-align:left;vertical-align:top;" headers="d54316e206 d54316e215 ">
              <ul>
                <li>ShippingContactInvalid</li>

                <li>BillingContactInvalid</li>

                <li>AddressUnserviceable</li>

                <li>CouponCodeInvalid</li>

                <li>CouponCodeExpired</li>

                <li>Unknown</li>

              </ul>
            </td>

          </tr>
        </tbody>
      </table>

#### See Also

- [Understand System Bot Dialogs](https://help.salesforce.com/s/articleView?id=service.bots_service_system_bot_dialog.htm&release=264.0.0&type=5 "Einstein Bots are built for conversation. To make setup a breeze, some of the most common dialogs are included with each new bot. These dialogs allow you to quickly transfer conversations to a service rep, or gracefully end a chat. You can customize each message to your company’s voice and tone.")