# Response and Error Codes

This page summarizes how the SDK represents operation outcomes and error conditions. All repository calls return a `RepositoryResult<T>` wrapper which forces you to handle success and failure explicitly.

## RepositoryResult&lt;T>

`RepositoryResult<T>` is a Kotlin sealed class with the following branches:

- **Success&lt;T>**: The call completed successfully.
  - Contains a `data: T` payload (for example `PaymentResult`, `RefundResult`, `TpvInfo`, `TotalsResult`, etc.).
- **ConnectionError**: A communication problem occurred.
  - Typical causes: the Get Smart SDK Payment Service is not running, the device is offline, or there is a connectivity issue with the host.
- **Cancelled**: The operation was cancelled.
  - Often indicates that the user aborted an interactive flow on the TPV UI. Includes a human‑readable `message`.
- **ProtocolError**: The request could not be processed due to an integration or mapping issue.
  - Includes a `type: ProtocolErrorType` and an optional `description`.

For idiomatic handling patterns and examples, see **`Core Concepts / Handle Responses and Errors`**.

## ProtocolErrorType

When you receive `RepositoryResult.ProtocolError`, the `type` field is one of the following values (see also **Data Models Glossary**):

- **`MAPPING_DATA`**: Internal error mapping data between the SDK and the background service.
  - Action: usually indicates an unexpected state; capture logs and contact support if it persists.
- **`MAPPING_DOMAIN`**: Something is wrong with the data your app sent.
  - Action: validate parameters such as amounts, currencies, and identifiers.
- **`TPV_NOT_INITIALIZED`**: A critical configuration error.
  - Action: ensure `InitializationRepository.initTpv()` has been called successfully before performing operations like payments, refunds, or history queries.

## Business‑level results

Many successful calls still require you to check a **business result** inside the payload:

- Payment, refund and preauthorization operations return sealed result types such as `PaymentResult`, `RefundResult`, and `PreauthorizationResult`, which distinguish:
  - **Accepted** operations (authorized by the host, with a `Transaction` payload).
  - **Denied** operations (rejected by the host/bank, with an explanatory `Transaction` payload).
  - Specific domain errors (for example `RefundResult.ExceededAmount`).
- History and totals queries return structures like `GetTransactionsResult` or `TotalsResult` which indicate whether there is data, more pages, or invalid identifiers.

<Callout type="warning">

Always inspect both the outer `RepositoryResult<T>` and the inner domain result to decide what to show in your UI and when to retry or escalate errors.

</Callout>