<commit_before>import { Router } from 'express';
import { CSP } from '../../types/namespaces/ChainStateProvider';
import { ChainStateProvider } from '../../providers/chain-state';
import logger from '../../logger';
const router = Router({ mergeParams: true });

router.get('/', function(req, res) {
  let { chain, network } = req.params;
  if (!chain || !network) {
    return res.status(400).send('Missing required param');
  }
  chain = chain.toUpperCase();
  network = network.toLowerCase();
  let payload: CSP.StreamTransactionsParams = {
    chain,
    network,
    stream: res,
    args: {}
  };
  if (req.query.blockHeight) {
    payload.args.blockHeight = parseInt(req.query.blockHeight);
  }
  if (req.query.blockHash) {
    payload.args.blockHash = req.query.blockHash;
  }
  return ChainStateProvider.streamTransactions(payload);
});

router.get('/:txId', function(req, res) {
  let { chain, network, txId } = req.params;
  if (typeof txId !== 'string' || !chain || !network) {
    return res.status(400).send('Missing required param');
  }
  chain = chain.toUpperCase();
  network = network.toLowerCase();
  return ChainStateProvider.streamTransaction({ chain, network, txId, stream: res });
});

router.post('/send', async function(req, res) {
  try {
    let { chain, network } = req.params;
    let { rawTx } = req.body;
    chain = chain.toUpperCase();
    network = network.toLowerCase();
    let txid = await ChainStateProvider.broadcastTransaction({
      chain,
      network,
      rawTx
    });
    return res.send({ txid });
  } catch (err) {
    logger.error(err);
    return res.status(500).send(err);
  }
});
module.exports = {
  router: router,
  path: '/tx'
};
<commit_msg>better error message<commit_after>import { Router } from 'express';
import { CSP } from '../../types/namespaces/ChainStateProvider';
import { ChainStateProvider } from '../../providers/chain-state';
import logger from '../../logger';
const router = Router({ mergeParams: true });

router.get('/', function(req, res) {
  let { chain, network } = req.params;
  if (!chain || !network) {
    return res.status(400).send('Missing required param');
  }
  chain = chain.toUpperCase();
  network = network.toLowerCase();
  let payload: CSP.StreamTransactionsParams = {
    chain,
    network,
    stream: res,
    args: {}
  };
  if (req.query.blockHeight) {
    payload.args.blockHeight = parseInt(req.query.blockHeight);
  }
  if (req.query.blockHash) {
    payload.args.blockHash = req.query.blockHash;
  }
  return ChainStateProvider.streamTransactions(payload);
});

router.get('/:txId', function(req, res) {
  let { chain, network, txId } = req.params;
  if (typeof txId !== 'string' || !chain || !network) {
    return res.status(400).send('Missing required param');
  }
  chain = chain.toUpperCase();
  network = network.toLowerCase();
  return ChainStateProvider.streamTransaction({ chain, network, txId, stream: res });
});

router.post('/send', async function(req, res) {
  try {
    let { chain, network } = req.params;
    let { rawTx } = req.body;
    chain = chain.toUpperCase();
    network = network.toLowerCase();
    let txid = await ChainStateProvider.broadcastTransaction({
      chain,
      network,
      rawTx
    });
    return res.send({ txid });
  } catch (err) {
    logger.error(err);
    return res.status(500).send(err.message);
  }
});
module.exports = {
  router: router,
  path: '/tx'
};

{'fraction_non_alphanumeric': 0.16476441322797775, 'fraction_numerical': 0.0052677787532923615, 'mean_word_length': 3.4505208333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4728281', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1078, 'n_words': 246}