> ## Documentation Index
> Fetch the complete documentation index at: https://docs.clickterm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Promise results & errors

> Handle SDK results and errors using Promises in the ClickTerm React Native SDK.

The ClickTerm React Native SDK is **Promise-based**. `show()` and `showAcceptedContent()` return Promises that resolve on success and reject with an `Error` (carrying a `.code` property) on failure.

## Show result

When `show()` completes:

```ts theme={null}
import * as Clickterm from '@clickterm/react-native-sdk';

try {
  const signature = await Clickterm.show(request);
  if (signature !== null) {
    // User accepted or declined — send Signature to your backend
    await sendToBackend(signature);
  } else {
    // User already accepted the latest major version — no dialog was shown
    console.log('Already accepted.');
  }
} catch (error) {
  // SDK or network error — inspect the code
  console.error('Clickwrap error', error);
}
```

### Possible outcomes

| Outcome               | Promise state | Resolved value                                              |
| --------------------- | ------------- | ----------------------------------------------------------- |
| User accepts          | Resolved      | Non-null Signature string — send it to your backend         |
| User declines         | Resolved      | Non-null Signature string — verify it to record the decline |
| User already accepted | Resolved      | `null` — no dialog was shown, no action needed              |
| Error                 | Rejected      | N/A — the rejection is an `Error` with a `.code` property   |

<Note>
  A `null` Signature resolved from `show()` means the user has already accepted the latest major version. No action is needed on your part.
</Note>

## Error handling

Errors are thrown as standard `Error` instances with a non-standard `code` property whose value is one of the documented `ClicktermErrorCode` strings. Read `code` from the caught error to drive your application's response:

```ts theme={null}
function formatError(error: unknown): string {
  if (error instanceof Error) {
    const code = (error as { code?: string }).code;
    return code ? `[${code}] ${error.message}` : error.message;
  }
  return String(error);
}

try {
  await Clickterm.show(request);
} catch (error) {
  console.error(formatError(error));
}
```

### `ClicktermErrorCode` values

| Code                             | Meaning                                                                            |
| -------------------------------- | ---------------------------------------------------------------------------------- |
| `ERR_CLICKTERM_NOT_INITIALIZED`  | `initialize()` was not called (or did not resolve) before invoking another method. |
| `ERR_CLICKTERM_INVALID_ARGUMENT` | A required field is missing or malformed (for example, an empty `appId`).          |
| `ERR_CLICKTERM_NETWORK`          | The device could not reach the ClickTerm API.                                      |
| `ERR_CLICKTERM_HTTP`             | The API responded with a non-success HTTP status.                                  |
| `ERR_CLICKTERM_DECODING`         | The SDK could not decode the response payload.                                     |
| `ERR_CLICKTERM_USER_CANCELLED`   | The user dismissed the dialog without acting on it.                                |
| `ERR_CLICKTERM_NO_PRESENTER`     | **iOS only** — no view controller was available to present the dialog.             |
| `ERR_CLICKTERM_NO_ACTIVITY`      | **Android only** — no foreground Activity was available to host the dialog.        |
| `ERR_CLICKTERM_UNKNOWN`          | An unexpected error occurred. Check the message for details.                       |

<Note>
  `ERR_CLICKTERM_NO_PRESENTER` and `ERR_CLICKTERM_NO_ACTIVITY` are platform-specific; you typically only see the one that matches the OS your app is running on.
</Note>

## Show accepted content result

`showAcceptedContent()` follows the same pattern: it resolves with the stored `ClickwrapTemplateContent` or rejects with an `Error` whose `code` is a `ClicktermErrorCode`.

```ts theme={null}
try {
  const content = await Clickterm.showAcceptedContent(request);
  // content.content is the rendered HTML of the accepted agreement
  console.log(content.title ?? '(untitled)');
} catch (error) {
  console.error('showAcceptedContent() failed', error);
}
```

<Note>
  `showAcceptedContent` only works if the end user has an accepted and verified event for the given template.
</Note>
