# Обробка помилок

SDK використовує типізовані помилки для точного визначення причини відмови.

| **Клас помилки**         | **Опис**                                                                              |
| ------------------------ | ------------------------------------------------------------------------------------- |
| `ValidationException`    | Дані не пройшли перевірку за схемою DTO (відсутні обов'язкові поля або невірний тип). |
| `AuthorizationException` | Помилки авторизації, невірні ключі або прострочені сесії.                             |
| `PaymentException`       | Помилки на рівні платіжної логіки (наприклад, недостатньо коштів для повернення).     |
| `AllianceSdkException`   | Базовий клас для всіх кастомних помилок SDK.                                          |

**Приклад перевірки помилок:**

```
import { ValidationException, AllianceSdkException } from '@alliancepay/sdk-nodejs';

try {
    await client.createOrder(orderData);
} catch (error) {
    if (error instanceof ValidationException) {
        // error.errors містить масив усіх знайдених помилок валідації DTO
        console.error('Validation errors:', error.errors);
    } else if (error instanceof AllianceSdkException) {
        // Обробка бізнес-помилок банку
        console.error(`Bank Error Code: ${error.code}`); // напр. 'b_terminal_not_found'
        console.error(`Message: ${error.message}`);
        console.error(`Raw Response Data:`, error.originalError); // Тіло відповіді банку
    } else {
        console.error('Unexpected system error:', error);
    }
}
```


---

# 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.merchant.alb.ua/platizhni-vidzheti-dlya-cms/nodejs-sdk/obrobka-pomilok.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.
