प्रत्येक त्रुटि प्रतिक्रिया में दो फ़ील्ड हैं: error (machine-readable, स्थिर, संस्करणों के बीच कभी नहीं बदलता है) और message (human-readable, समय के साथ सुधार किया जा सकता है)। हमेशा अपने कोड में error पर स्विच करें। message को उपयोगकर्ताओं को प्रदर्शित करें।

त्रुटि प्रारूप

सभी त्रुटि प्रतिक्रियाएं एक ही संरचना का पालन करती हैं:

त्रुटि प्रतिक्रिया
{ "error": "error_code_here", "message": "Human-readable explanation" }

कुछ त्रुटियों में अतिरिक्त फील्ड होते हैं: ref (delegation attempt के लिए एक reference ID) और refund (automatic refund के बारे में विवरण)।

Validation Errors

Error CodeHTTPकारणसमाधान
invalid_tx_hash400tx_hash 64-character hex string नहीं हैhash format को check करें। बिल्कुल 64 hex characters होने चाहिए, कोई prefix नहीं।
invalid_address400delegate_to एक valid Tron address नहीं हैcall करने से पहले TronWeb.isAddress() से address को validate करें।
missing_signature400request में कोई signature प्रदान नहीं किया गयाmessage को sign करें {tx_hash}:{delegate_to} के साथ tronWeb.trx.signMessageV2() उस wallet से जिसने TRX भेजा है।
invalid_signature401Signature को verify नहीं किया जा सकासुनिश्चित करें कि आपने बिल्कुल {tx_hash}:{delegate_to} (lowercase hex hash, colon, exact Tron address) को sign किया है।
signature_mismatch403Signer address payment भेजने वाले से मेल नहीं खाताSignature उसी wallet से आना चाहिए जिसने TRX payment भेजा है। अलग wallet = rejected।

Payment Errors

Error CodeHTTPकारणसमाधान
payment_verification_failed404 / 400on-chain payment को verify नहीं किया जा सका। message field specific कारण बताता है।आम कारण: tx अभी confirmed नहीं हुआ है (3-5 seconds प्रतीक्षा करें और फिर से retry करें), गलत recipient address, transaction एक TRX transfer नहीं है, 4 TRX minimum से कम है।
hash_already_used409इस tx hash को पहले ही claim किया जा चुका हैप्रत्येक payment hash को केवल एक बार use किया जा सकता है। नए delegation के लिए नया payment भेजें।

Service Errors

Error CodeHTTPकारणसमाधान
delegation_failed400 / 500Provider energy delegation deliver नहीं कर सकाअगर failure आपके payment verify होने के बाद हुई है, तो एक automatic refund queue में है। check करें refund ऑब्जेक्ट। अन्यथा दोबारा कोशिश करें, या support से संपर्क करें ref ID।
rate_limited429इस IP से बहुत सारे अनुरोधगति कम करें और दोबारा कोशिश करें। सीमा 20 अनुरोध प्रति सेकंड है।
server_error500अप्रत्याशित आंतरिक त्रुटिकुछ सेकंड के बाद दोबारा कोशिश करें। यदि समस्या बनी रहे, तो support से संपर्क करें ref यदि उपलब्ध हो।

कोड में त्रुटियों को संभालना

अनुशंसित त्रुटि हैंडलिंग
const result = await fetch('https://api.tronnrg.com/delegate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tx_hash: hash, delegate_to: addr, signature: sig }), }).then(r => r.json()); if (result.error) { switch (result.error) { case 'payment_verification_failed': // Most common: tx not yet indexed. Wait 3s and retry once. await new Promise(r => setTimeout(r, 3000)); return retry(hash, addr); case 'hash_already_used': // Already claimed. Don't retry. throw new Error('Duplicate delegation attempt'); case 'signature_mismatch': // Signer != payment sender. Sign with the same key. throw new Error('Signer does not match payment sender'); case 'delegation_failed': // Refund queued automatically if payment was verified. if (result.refund) console.log('Refund queued:', result.refund); break; default: console.error(result.error, result.message); } return; } // Success console.log('Delegated:', result.energy, 'energy'); console.log('Delegation tx:', result.delegations[0].tx); // verify on TronScan console.log('Ref:', result.ref);
Telegram WhatsApp