> ## Documentation Index
> Fetch the complete documentation index at: https://shinydapps-bd9fa40b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Reference

> एजेंट और डेवलपर्स के लिए l402-kit से semantic error codes।

l402-kit के सभी errors एक structured JSON format का पालन करते हैं ताकि एजेंट उन्हें programmatically parse करके उन पर कार्य कर सकें।

```json theme={null}
{
  "error": "ERROR_CODE",
  "code": 402,
  "cause": "Human-readable explanation",
  "action": "recommended_action",
  "retry": false
}
```

***

## Error codes

### PAYMENT\_FAILED

```json theme={null}
{
  "error": "PAYMENT_FAILED",
  "code": 402,
  "cause": "Insufficient balance in wallet",
  "action": "increase_budget",
  "retry": false
}
```

Wallet invoice का भुगतान नहीं कर सका। balance और `budgetSats` limit जांचें।

***

### TOKEN\_EXPIRED

```json theme={null}
{
  "error": "TOKEN_EXPIRED",
  "code": 402,
  "cause": "Macaroon expiry timestamp exceeded",
  "action": "request_new_invoice",
  "retry": true
}
```

L402 token बनाया गया था लेकिन अपने TTL (default: 1 घंटा) से पहले उपयोग नहीं किया गया। नया invoice प्राप्त करने के लिए request दोबारा करें।

***

### BUDGET\_EXCEEDED

```json theme={null}
{
  "error": "BUDGET_EXCEEDED",
  "code": 402,
  "cause": "Session budget of {n} sats exhausted",
  "action": "stop_or_increase_budget",
  "retry": false
}
```

एजेंट ने वर्तमान session में `budgetSats` से अधिक खर्च कर दिया है। budget बढ़ाएं या session समाप्त करें।

***

### INVALID\_MACAROON

```json theme={null}
{
  "error": "INVALID_MACAROON",
  "code": 402,
  "cause": "Macaroon is not valid base64 JSON",
  "action": "request_new_invoice",
  "retry": true
}
```

macaroon को decode नहीं किया जा सका। आमतौर पर एक corrupted token के कारण होता है। शुरू से दोबारा प्रयास करें।

***

### TOKEN\_ALREADY\_USED

```json theme={null}
{
  "error": "TOKEN_ALREADY_USED",
  "code": 401,
  "cause": "Preimage was already presented — replay attack blocked",
  "action": "do_not_retry",
  "retry": false
}
```

Replay protection सक्रिय हुई। प्रत्येक preimage केवल एक बार उपयोग किया जा सकता है। tokens को कभी भी दोबारा उपयोग न करें।

***

### NODE\_UNREACHABLE

```json theme={null}
{
  "error": "NODE_UNREACHABLE",
  "code": 503,
  "cause": "Lightning node did not respond within timeout",
  "action": "retry_with_backoff",
  "retry": true
}
```

Lightning provider अनुपलब्ध है। exponential backoff के साथ दोबारा प्रयास करें।

***

### INVOICE\_EXPIRED

```json theme={null}
{
  "error": "INVOICE_EXPIRED",
  "code": 402,
  "cause": "BOLT11 invoice expired before payment was submitted",
  "action": "request_new_invoice",
  "retry": true
}
```

BOLT11 invoices की समय सीमा समाप्त हो जाती है (default: 600 seconds)। नया invoice प्राप्त करने के लिए original request दोबारा करें।

***

### WRONG\_PREIMAGE

```json theme={null}
{
  "error": "WRONG_PREIMAGE",
  "code": 402,
  "cause": "SHA256(preimage) does not match paymentHash in macaroon",
  "action": "check_wallet_payment",
  "retry": false
}
```

Cryptographic verification विफल हुई। preimage इस invoice के भुगतान को प्रमाणित नहीं करता।

***

## एजेंट में errors को handle करना

```typescript theme={null}
import { l402 } from "l402-kit/agent";

try {
  const res = await client.fetch("https://api.example.com/data");
} catch (err: any) {
  if (err.error === "BUDGET_EXCEEDED") {
    // stop and report to user
  } else if (err.retry === true) {
    // safe to retry after short delay
    await sleep(1000);
    const res = await client.fetch("https://api.example.com/data");
  }
}
```
