---
title: "urlSession(_:task:didCompleteWithError:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsessiontaskdelegate/urlsession(_:task:didcompletewitherror:)"
---

# urlSession(_:task:didCompleteWithError:)

Tells the delegate that the task finished transferring data.

## Declaration

```swift
optional func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: (any Error)?)
```

## Parameters

- `session`: The session containing the task that has finished transferring data.
- `task`: The task that has finished transferring data.
- `error`: If an error occurred, an error object indicating how the transfer failed, otherwise NULL.

## Mentioned in

Pausing and resuming downloads Downloading files from websites Fetching website data into memory Pausing and resuming uploads

## Discussion

Discussion The only errors your delegate receives through the error parameter are client-side errors, such as being unable to resolve the hostname or connect to the host. To check for server-side errors, inspect the response property of the task parameter received by this callback.
