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

# Error Handling

> PayKit methods throw on failure. Wrap with try/catch to handle errors.

PayKit methods return the result directly. Wrap with `try/catch` to handle errors:

```typescript theme={null}
try {
  const customer = await paykit.customers.create({
    email: 'user@example.com',
    name: 'Jane Doe',
  });
  console.log(customer.id);
} catch (error) {
  console.error(error.message);
}
```

## Error types

Import from `@paykit-sdk/core`:

```typescript theme={null}
import {
  ValidationError,
  ConfigurationError,
  ProviderNotSupportedError,
  NotImplementedError,
} from '@paykit-sdk/core';
```

| Error                       | When                                       |
| --------------------------- | ------------------------------------------ |
| `ValidationError`           | Input fails schema validation              |
| `ConfigurationError`        | Provider misconfigured or missing env vars |
| `ProviderNotSupportedError` | Operation not supported by this provider   |
| `NotImplementedError`       | Operation planned but not yet built        |

## Example

```typescript theme={null}
try {
  const checkout = await paykit.checkouts.create({
    customer: 'cus_123',
    item_id: 'price_123',
    session_type: 'one_time',
    quantity: 1,
    success_url: 'https://example.com/success',
    cancel_url: 'https://example.com/cancel',
  });
  redirect(checkout.payment_url);
} catch (error) {
  if (error instanceof ValidationError) {
    return res.status(400).json({ error: error.message });
  }
  if (error instanceof ProviderNotSupportedError) {
    return res.status(501).json({ error: 'Not supported by this provider' });
  }
  return res.status(500).json({ error: 'Unexpected error' });
}
```
