# Manage Exceptions

You can control which URLs are permitted to bypass the blocking rules by granting an exception for a specific web page, or an entire host. However, on iOS, exceptions may only be applied to an entire host.

## Get the Exceptions List

To get the list of exceptions you can use the `getExceptions` method.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { FilterException } from '@sudoplatform/sudo-ad-tracker-blocker'

const exceptions: FilterException[] = await client.getExceptions()
```

{% endtab %}

{% tab title="Swift" %}

```swift
let client: SudoAdTrackerBlockerClient!
let exceptions = await client.getExceptions()
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// val client: SudoAdTrackerBlockerClient

launch {
    try {
        val isMySiteExcepted = withContext(Dispatchers.IO) {
            client.getExceptions().firstOrNull { exc ->
                exc.source.contains("http://myfavourite.domain.eu")
            }        
        } ?: false
    } catch (e: SudoAdTrackerBlockerException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}

## Add to the Exceptions List

To add to the list of exceptions you can use the `addExceptions` method. You can add the URL of a single page or an entire host to the list of exceptions.

On iOS, exceptions may only apply to an entire host.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { FilterException } from '@sudoplatform/sudo-ad-tracker-blocker'

const hostException: FilterException = {
  // `type` === 'host' prevents blocking on 
  // any pages at `example.com`.
  type: 'host',
  source: 'http://example.com/page.html'
}

const pageException: FilterException = {
  // `type` === 'page' prevents blocking on 
  // only `example.com/page.html`.
  type: 'page',
  source: 'https://example.com/page.html'
}

// Add both exceptions to the exceptions list
await client.addExceptions([
  hostException, 
  pageException
])
```

{% endtab %}

{% tab title="Swift" %}

```swift
let client: SudoAdTrackerBlockerClient!
await client.addExceptions([BlockingException("example.com")])
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// val client: SudoAdTrackerBlockerClient

launch {
    try {
        withContext(Dispatchers.IO) {
            client.addExceptions(
                toHostException("http://somehost.com"),
                toPageException("http://myfavourite.domain.eu/homepage")
            )
        }
    } catch (e: SudoAdTrackerBlockerException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}

## Remove from the Exceptions List

To remove from the list of exceptions you can use the `removeExceptions` method. You should supply the same exception value(s) you used when you added the page or host to the list of exceptions.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
const exception: FilterException = {
  type: 'host',
  source: 'http://example.com/page.html'
}

/*
 * The `removeExceptions` method returns a Promise that will
 * resolve when the exception has been removed from the 
 * storage provider provided to the client.
 *
 * In this case the removed exception will be for all pages 
 * of `example.com` since the exception is of type `host`.
 */

await client.removeExceptions([exception])
```

{% endtab %}

{% tab title="Swift" %}

```swift
let client: SudoAdTrackerBlockerClient!
await client.removeExceptions([BlockingException("example.com")])
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// val client: SudoAdTrackerBlockerClient

launch {
    try {
        withContext(Dispatchers.IO) {
            client.removeExceptions(
                toHostException("http://somehost.com"),
                toPageException("http://myfavourite.domain.eu/homepage")
            )
        }
    } catch (e: SudoAdTrackerBlockerException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}

## Removing all the Entries from the Exceptions List

To remove all entries from the list of exceptions you can use the `removeAllExceptions` method.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
/*
 * The `removeAllExceptions` method returns a Promise that 
 * will resolve when the all of the exceptions have succesfully
 * been removed from the client's storage provider.
 */

await client.removeAllExceptions()
```

{% endtab %}

{% tab title="Swift" %}

<pre class="language-swift"><code class="lang-swift">let client: SudoAdTrackerBlockerClient!
<strong>await client.removeAllExceptions()
</strong></code></pre>

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// val client: SudoAdTrackerBlockerClient

launch {
    try {
        withContext(Dispatchers.IO) {
            client.removeAllExceptions()
        }
    } catch (e: SudoAdTrackerBlockerException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sudoplatform.com/guides/ad-tracker-blocker/manage-exceptions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
