From d998b005925348962eb54ae52d781a654a0f9120 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 5 Dec 2016 12:10:32 +0100 Subject: [PATCH] Return information about the exception --- bigchaindb/web/views/transactions.py | 35 +++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/bigchaindb/web/views/transactions.py b/bigchaindb/web/views/transactions.py index e2abeb48..babec6fc 100644 --- a/bigchaindb/web/views/transactions.py +++ b/bigchaindb/web/views/transactions.py @@ -7,9 +7,16 @@ from flask import current_app, request, Blueprint from flask_restful import Resource, Api from bigchaindb.common.exceptions import ( - ValidationError, + AmountError, + DoubleSpend, + InvalidHash, InvalidSignature, SchemaValidationError, + OperationError, + TransactionDoesNotExist, + TransactionOwnerError, + TransactionNotInValidBlock, + ValidationError, ) import bigchaindb @@ -108,16 +115,32 @@ class TransactionListApi(Resource): message='Invalid transaction schema: {}'.format( e.__cause__.message) ) - except (ValidationError, InvalidSignature): - return make_error(400, 'Invalid transaction') + except (ValidationError, InvalidSignature) as e: + return make_error( + 400, + 'Invalid transaction ({}): {}'.format(type(e).__name__, e) + ) with pool() as bigchain: - if bigchain.is_valid_transaction(tx_obj): + try: + bigchain.validate_transaction(tx_obj) + except (ValueError, + OperationError, + TransactionDoesNotExist, + TransactionOwnerError, + DoubleSpend, + InvalidHash, + InvalidSignature, + TransactionNotInValidBlock, + AmountError) as e: + return make_error( + 400, + 'Invalid transaction ({}): {}'.format(type(e).__name__, e) + ) + else: rate = bigchaindb.config['statsd']['rate'] with monitor.timer('write_transaction', rate=rate): bigchain.write_transaction(tx_obj) - else: - return make_error(400, 'Invalid transaction') return tx