From 74fa3c7eb1654279c1454c04d1c47b6ad3827827 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 1 Jan 2025 16:51:34 +0000 Subject: [PATCH] conform getPrevouts and getCpfpLocalTx to new error handling standard --- backend/src/api/bitcoin/bitcoin.routes.ts | 25 +++++++++++-------- .../transaction/transaction-raw.component.ts | 5 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/backend/src/api/bitcoin/bitcoin.routes.ts b/backend/src/api/bitcoin/bitcoin.routes.ts index f92b7cd0c..0e9016bde 100644 --- a/backend/src/api/bitcoin/bitcoin.routes.ts +++ b/backend/src/api/bitcoin/bitcoin.routes.ts @@ -936,11 +936,13 @@ class BitcoinRoutes { try { const outpoints = req.body; if (!Array.isArray(outpoints) || outpoints.some((item) => !/^[a-fA-F0-9]{64}$/.test(item.txid) || typeof item.vout !== 'number')) { - return res.status(400).json({ message: 'Invalid input format' }); + handleError(req, res, 400, 'Invalid outpoints format'); + return; } if (outpoints.length > 100) { - return res.status(400).json({ message: 'Too many prevouts requested' }); + handleError(req, res, 400, 'Too many outpoints requested'); + return; } const result = Array(outpoints.length).fill(null); @@ -955,7 +957,7 @@ class BitcoinRoutes { if (mempoolTx) { if (outpoint.vout < mempoolTx.vout.length) { prevout = mempoolTx.vout[outpoint.vout]; - unconfirmed = true; + unconfirmed = true; } } else { const rawPrevout = await bitcoinClient.getTxOut(outpoint.txid, outpoint.vout, false); @@ -979,7 +981,7 @@ class BitcoinRoutes { res.json(result); } catch (e) { - handleError(req, res, 500, e instanceof Error ? e.message : e); + handleError(req, res, 500, 'Failed to get prevouts'); } } @@ -988,22 +990,23 @@ class BitcoinRoutes { const tx = req.body; if ( - !tx || typeof tx !== "object" || - !tx.txid || typeof tx.txid !== "string" || - typeof tx.weight !== "number" || - typeof tx.sigops !== "number" || - typeof tx.fee !== "number" || + !tx || typeof tx !== 'object' || + !tx.txid || typeof tx.txid !== 'string' || + typeof tx.weight !== 'number' || + typeof tx.sigops !== 'number' || + typeof tx.fee !== 'number' || !Array.isArray(tx.vin) || !Array.isArray(tx.vout) ) { - return res.status(400).json({ message: 'Invalid transaction format: missing or incorrect fields' }); + handleError(req, res, 400, 'Invalid transaction format'); + return; } const cpfpInfo = calculateLocalTxCpfp(tx, mempool.getMempool()); res.json(cpfpInfo); } catch (e) { - handleError(req, res, 500, e instanceof Error ? e.message : e); + handleError(req, res, 500, 'Failed to calculate CPFP info'); } } } diff --git a/frontend/src/app/components/transaction/transaction-raw.component.ts b/frontend/src/app/components/transaction/transaction-raw.component.ts index 441a72f61..80f3eeb93 100644 --- a/frontend/src/app/components/transaction/transaction-raw.component.ts +++ b/frontend/src/app/components/transaction/transaction-raw.component.ts @@ -143,7 +143,8 @@ export class TransactionRawComponent implements OnInit, OnDestroy { this.isLoadingPrevouts = false; this.fetchCpfp = prevouts.some(prevout => prevout?.unconfirmed); } catch (error) { - this.errorPrevouts = error?.error?.message || error?.message; + console.log(error); + this.errorPrevouts = error?.error?.error || error?.message; this.isLoadingPrevouts = false; } } @@ -171,7 +172,7 @@ export class TransactionRawComponent implements OnInit, OnDestroy { } this.isLoadingCpfpInfo = false; } catch (error) { - this.errorCpfpInfo = error?.error?.message || error?.message; + this.errorCpfpInfo = error?.error?.error || error?.message; this.isLoadingCpfpInfo = false; } }