> For the complete documentation index, see [llms.txt](https://bify.gitbook.io/rwa-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bify.gitbook.io/rwa-docs/bify-sdk/errors.md).

# Errors and Recovery

The SDK converts validation, API, timeout, and network failures into typed errors. Customer interfaces should show a safe, actionable message and keep provider details in server-side operational logs only.

## Error classes

```ts
import {
  BifyApiError,
  BifyNetworkError,
  BifyTimeoutError,
  BifyValidationError,
} from "@bify/sdk";

try {
  await bify.checkout.createOrderSession(input);
} catch (error) {
  if (error instanceof BifyValidationError) {
    // Fix the request before retrying. Do not retry unchanged input.
    return showPartnerConfigurationError(error.message);
  }

  if (error instanceof BifyApiError) {
    // Use status and code for controlled server behavior. requestId is safe
    // to attach to an internal support record.
    console.error({ status: error.status, code: error.code, requestId: error.requestId });
    if (error.retriable) return retryWithTheSameIdempotencyKey();
    return showCustomerMessage("Checkout could not be started.");
  }

  if (error instanceof BifyTimeoutError || error instanceof BifyNetworkError) {
    return showCustomerMessage("BIFY could not be reached. Please try again.");
  }

  return showCustomerMessage("The request could not be completed.");
}
```

## Retry rules

* Retry a network or timeout failure only with the same idempotency key.
* Do not create a new checkout session for every browser retry.
* Treat a successful response followed by a client timeout as unknown state; retrieve the order before creating another session.
* Do not retry validation errors without changing the input.
* Do not retry a payment confirmation indefinitely. Reconcile the transaction hash and session status.
* Process a webhook event once by storing its event ID before applying its business transition.

## Safe error handling

Do not expose API keys, webhook secrets, request signatures, raw provider payloads, encrypted fields, database errors, or stack traces to customers. Use the request ID returned by the SDK for support correlation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://bify.gitbook.io/rwa-docs/bify-sdk/errors.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
