---
schema_version: "1"
id: b44dada162e4f76a21b5d411e0d382af4e57ae1a770ac34b57f82f21daeef1d7
title: Cancel an Asynchronous Request in a Flow Local Action
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/components/components-config-for-flow-actions-abort.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/components-config-for-flow-actions-abort.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7eb3cdbcd02260af9356ed41ad1ee461dba594f44c46fb944ea001e68c9239a7
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Cancel an Asynchronous Request in a Flow Local Action

If an asynchronous request times out, the flow executes the local action's fault connector and sets `$Flow.FaultMessage` to the error message. However, the original request isn't automatically canceled. To abort an asynchronous request, use the `cancelToken` parameter available in the `invoke` method.

**note:** By default, requests time out after 120 seconds. To override the default, assign a different Integer to the component's `timeout` attribute.

In this client-side controller, the `invoke` method returns a Promise. When the method has done all it needs to do, it completes the call and control returns to the flow.

- If the request is successful, the method uses `resolve()` to execute the next element in the flow after this action.
- If the request isn't successful, it uses `reject()` to execute the local action’s fault connector and sets `$Flow.FaultMessage` to “My error message”.
- If the request takes too long, it uses `cancelToken.promise.then` to abort the request.

```nolang
({
   invoke : function(component, event, helper) {
      var cancelToken = event.getParam("arguments").cancelToken;

      return new Promise(function(resolve, reject) {
         var xhttp = new XMLHttpRequest();

         // Do something, like get data from
         // a database behind your firewall
         xhttp.onreadystatechange = $A.getCallback(function() {
            if (/* request was successful */) {
               // Complete the call and return to the flow
               resolve();
            } else {
               reject(new Error("My error message"));
            }
         });

         // If the Promise times out, abort the request and
         // pass set $Flow.FaultMessage to "Request timed out"
         cancelToken.promise.then(function(error) {
            xhttp.abort();
            reject(new Error("Request timed out."));
         });

      });
   }
})
```

**See Also**

- [_Component Library_: lightning:availableForFlowActions Interface](https://developer.salesforce.com/docs/component-library/bundle/lightning:availableForFlowActions/documentation)

- [Configure the Client-Side Controller for a Flow Local Action](https://developer.salesforce.com/docs/platform/aura-platform/guide/components-config-for-flow-actions-controller.md)
