Skip to main content
l402-kit के सभी errors एक structured JSON format का पालन करते हैं ताकि एजेंट उन्हें programmatically parse करके उन पर कार्य कर सकें।
{
  "error": "ERROR_CODE",
  "code": 402,
  "cause": "Human-readable explanation",
  "action": "recommended_action",
  "retry": false
}

Error codes

PAYMENT_FAILED

{
  "error": "PAYMENT_FAILED",
  "code": 402,
  "cause": "Insufficient balance in wallet",
  "action": "increase_budget",
  "retry": false
}
Wallet invoice का भुगतान नहीं कर सका। balance और budgetSats limit जांचें।

TOKEN_EXPIRED

{
  "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

{
  "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

{
  "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

{
  "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

{
  "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

{
  "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

{
  "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 करना

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");
  }
}