Skip to content

Commit

Permalink
Merge branch 'sendErrMessage' of github.com:leolambo/bitcore
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Apr 30, 2024
2 parents 01f9986 + e423b8c commit b77b6db
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 84 deletions.
48 changes: 24 additions & 24 deletions packages/bitcore-node/src/modules/ethereum/api/evmRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export class EVMRouter {
try {
const nonce = await this.csp.getAccountNonce(network, address);
res.json({ nonce });
} catch (err) {
logger.error('Nonce Error::%o', err);
res.status(500).send(err);
} catch (err: any) {
logger.error('Nonce Error::%o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});
};
Expand All @@ -61,8 +61,8 @@ export class EVMRouter {
if (err?.code != null) { // Preventable error from geth (probably due to insufficient funds or similar)
res.status(400).send(err.message);
} else {
logger.error('Gas Error::%o', err);
res.status(500).send(err);
logger.error('Gas Error::%o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
}
});
Expand All @@ -74,9 +74,9 @@ export class EVMRouter {
try {
const tokenInfo = await this.csp.getERC20TokenInfo(network, tokenAddress);
res.json(tokenInfo);
} catch (err) {
logger.error('Token Info Error::%o', err);
res.status(500).send(err);
} catch (err: any) {
logger.error('Token Info Error::%o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});
};
Expand All @@ -87,9 +87,9 @@ export class EVMRouter {
try {
const allowance = await this.csp.getERC20TokenAllowance(network, tokenAddress, ownerAddress, spenderAddress);
res.json(allowance);
} catch (err) {
logger.error('Token Allowance Error::%o', err);
res.status(500).send(err);
} catch (err: any) {
logger.error('Token Allowance Error::%o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});
};
Expand All @@ -107,7 +107,7 @@ export class EVMRouter {
}
return res.json(fee);
} catch (err: any) {
logger.error('Fee Error: %o', err.message || err);
logger.error('Fee Error: %o', err.stack || err.message || err);
return res.status(500).send('Error getting priority fee from RPC');
}
});
Expand All @@ -126,9 +126,9 @@ export class EVMRouter {
res,
args: req.query
});
} catch (err) {
logger.error('Multisig Transactions Error::%o', err);
return res.status(500).send(err);
} catch (err: any) {
logger.error('Multisig Transactions Error::%o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});
};
Expand All @@ -139,9 +139,9 @@ export class EVMRouter {
try {
const multisigTxpsInfo = await Gnosis.getMultisigTxpsInfo(network, multisigContractAddress);
res.json(multisigTxpsInfo);
} catch (err) {
logger.error('Multisig Txps Error::%o', err);
res.status(500).send(err);
} catch (err: any) {
logger.error('Multisig Txps Error::%o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});
};
Expand All @@ -152,9 +152,9 @@ export class EVMRouter {
try {
const multisigInstantiationInfo = await Gnosis.getMultisigContractInstantiationInfo(network, sender, txId);
res.json(multisigInstantiationInfo);
} catch (err) {
logger.error('Multisig Instantiation Error::%o', err);
res.status(500).send(err);
} catch (err: any) {
logger.error('Multisig Instantiation Error::%o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});
};
Expand All @@ -165,9 +165,9 @@ export class EVMRouter {
try {
const multisigInfo = await Gnosis.getMultisigEthInfo(network, multisigContractAddress);
res.json(multisigInfo);
} catch (err) {
logger.error('Multisig Info Error::%o', err);
res.status(500).send(err);
} catch (err: any) {
logger.error('Multisig Info Error::%o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});
};
Expand Down
16 changes: 10 additions & 6 deletions packages/bitcore-node/src/modules/ripple/api/xrp-routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Router } from 'express';
import logger from '../../../logger';
import { XRP } from './csp';
export const XrpRoutes = Router();

Expand All @@ -7,8 +8,9 @@ XrpRoutes.get('/api/XRP/:network/address/:address/txs/count', async (req, res) =
try {
const nonce = await XRP.getAccountNonce(network, address);
res.json({ nonce });
} catch (err) {
res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting XRP account nonce: %o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});

Expand All @@ -17,8 +19,9 @@ XrpRoutes.get('/api/XRP/:network/address/:address/flags', async (req, res) => {
try {
const flags = await XRP.getAccountFlags(network, address);
res.json({ flags });
} catch (err) {
res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting XRP account flags: %o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});

Expand All @@ -27,7 +30,8 @@ XrpRoutes.get('/api/XRP/:network/reserve', async (req, res) => {
try {
const reserve = await XRP.getReserve(network);
res.json({ reserve });
} catch (err) {
res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting XRP reserve: %o', err.stack || err.message || err);
res.status(500).send(err.message || err);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ export class BaseEVMStateProvider extends InternalStateProvider implements IChai
try {
const tokenTransfers = await this.getErc20Transfers(network, address, tokenAddress, args);
res!.json(tokenTransfers);
} catch (e) {
res!.status(500).send(e);
} catch (err: any) {
logger.error('Error streaming address transactions: %o', err.stack || err.message || err);
res!.status(500).send(err);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions packages/bitcore-node/src/routes/api/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function streamCoins(req, res) {
args: { ...req.query, unspent, limit, since }
};
ChainStateProvider.streamAddressTransactions(payload);
} catch (err) {
logger.error('Error streaming coins: %o', err);
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error streaming coins: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
}

router.get('/:address', function(req, res) {
router.get('/:address', function (req, res) {
try {
let { address, chain, network } = req.params;
let { unspent, limit = 10, since } = req.query;
Expand All @@ -35,16 +35,16 @@ router.get('/:address', function(req, res) {
args: { unspent, limit, since }
};
return ChainStateProvider.streamAddressUtxos(payload);
} catch (err) {
logger.error('Error getting address: %o', err);
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting address: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

router.get('/:address/txs', streamCoins);
router.get('/:address/coins', streamCoins);

router.get('/:address/balance', async function(req, res) {
router.get('/:address/balance', async function (req, res) {
let { address, chain, network } = req.params;
try {
let result = await ChainStateProvider.getBalanceForAddress({
Expand All @@ -54,9 +54,9 @@ router.get('/:address/balance', async function(req, res) {
args: req.query
});
return res.send(result || { confirmed: 0, unconfirmed: 0, balance: 0 });
} catch (err) {
logger.error('Error getting address balance: %o', err);
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting address balance: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand Down
27 changes: 16 additions & 11 deletions packages/bitcore-node/src/routes/api/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Request, Response } from 'express';
import logger from '../../logger';
import { CoinStorage, ICoin } from '../../models/coin';
import { TransactionStorage } from '../../models/transaction';
import { ChainStateProvider } from '../../providers/chain-state';
Expand All @@ -22,8 +23,9 @@ router.get('/', async function(req: Request, res: Response) {
res
};
return ChainStateProvider.streamBlocks(payload);
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting blocks: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand All @@ -32,9 +34,9 @@ router.get('/tip', async function(req: Request, res: Response) {
try {
let tip = await ChainStateProvider.getLocalTip({ chain, network });
return res.json(tip);
} catch (err) {
console.error(err);
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting tip block: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand All @@ -50,8 +52,9 @@ router.get('/:blockId', async function(req: Request, res: Response) {
SetCache(res, CacheTimes.Month);
}
return res.json(block);
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting blockId: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand Down Expand Up @@ -119,8 +122,9 @@ router.get('/:blockHash/coins/:limit/:pgnum', async function(req: Request, res:

const sanitize = (coins: Array<ICoin>) => coins.map(c => CoinStorage._apiTransform(c, { object: true }));
return res.json({ txids, inputs: sanitize(inputs), outputs: sanitize(outputs), previous, next });
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting block hash data: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand All @@ -136,8 +140,9 @@ router.get('/before-time/:time', async function(req: Request, res: Response) {
SetCache(res, CacheTimes.Month);
}
return res.json(block);
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting blocks before time: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand Down
6 changes: 4 additions & 2 deletions packages/bitcore-node/src/routes/api/stats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Request, Response } from 'express';
import logger from '../../logger';
import { ChainStateProvider } from '../../providers/chain-state';
import { CacheTimes, SetCache } from '../middleware';
const router = require('express').Router({ mergeParams: true });
Expand All @@ -18,8 +19,9 @@ router.get('/daily-transactions', async function(req: Request, res: Response) {
});
SetCache(res, CacheTimes.Day);
return res.json(dailyTxs);
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting daily transactions: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand Down
17 changes: 10 additions & 7 deletions packages/bitcore-node/src/routes/api/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ router.get('/:txId', async (req: Request, res: Response) => {
}
return res.send(tx);
}
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting transaction: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand Down Expand Up @@ -97,8 +98,9 @@ router.get('/:txId/populated', async (req: Request, res: Response) => {
tx.coins = coins;
return res.send(tx);
}
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting populated transaction: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand All @@ -116,8 +118,9 @@ router.get('/:txId/authhead', async (req: Request, res: Response) => {
} else {
return res.send(authhead);
}
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error getting transaction authhead: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand Down Expand Up @@ -156,7 +159,7 @@ router.post('/send', async function(req: Request, res: Response) {
});
return res.send({ txid });
} catch (err: any) {
logger.error('Broadcast error: %o %o %o %o', chain, network, rawTx, err);
logger.error('Broadcast error: %o %o %o %o', chain, network, rawTx, err.stack || err.message || err);
return res.status(500).send(err.message);
}
});
Expand Down
8 changes: 5 additions & 3 deletions packages/bitcore-node/src/routes/api/valid.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import express = require('express');
const router = express.Router({ mergeParams: true });
import logger from '../../logger';
import { ChainStateProvider } from '../../providers/chain-state';

router.get('/:input', async function(req, res) {
router.get('/:input', async function (req, res) {
let { input, chain, network } = req.params;
try {
let isValid = await ChainStateProvider.isValid({
Expand All @@ -11,8 +12,9 @@ router.get('/:input', async function(req, res) {
input
});
return res.send(isValid);
} catch (err) {
return res.status(500).send(err);
} catch (err: any) {
logger.error('Error checking network validity: %o', err.stack || err.message || err);
return res.status(500).send(err.message || err);
}
});

Expand Down
Loading

0 comments on commit b77b6db

Please sign in to comment.