---
title: "cancelRequest(withError:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsextensioncontext/cancelrequest(witherror:)"
---

# cancelRequest(withError:)

Tells the host app to cancel the app extension request, with a supplied error.

## Declaration

```swift
func cancelRequest(withError error: any Error)
```

## Parameters

- `error`: The error object to return. It must be non-nil.

## Discussion

Discussion On return, the userInfo dictionary of the NSError object contains a key named NSExtensionItemsAndErrorsKey which has as its value a dictionary of NSExtensionItem objects and associated NSError instances.

## See Also

### Related Documentation

- [App Extension Programming Guide](apple-archive/documentation/General/Conceptual/ExtensibilityPG.md)

### Handling requests

- [completeRequest(returningItems:completionHandler:)](foundation/nsextensioncontext/completerequest(returningitems:completionhandler:).md)
- [NSExtensionItemsAndErrorsKey](foundation/nsextensionitemsanderrorskey.md)
