mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 06:25:45 +00:00
catching Tarantool exceptions in case of concurrency (implicitly issued by the planetmint-diver-ts tests)
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
87506ff4a1
commit
d85ad2066e
@ -25,6 +25,9 @@ For reference, the possible headings are:
|
||||
* **Known Issues**
|
||||
* **Notes**
|
||||
|
||||
## [2.2.2] - 2023-31-01
|
||||
* **Fixed** catching tarantool exceptions in case tarantool drivers throw execeptions due to concurrency issues. This issue got idenitfied during the testing of the planetmint-driver-ts.
|
||||
|
||||
## [2.2.0] - 2023-31-01
|
||||
* **Changed** standardized blocks API
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
__version__ = "2.2.1"
|
||||
__version__ = "2.2.2"
|
||||
__short_version__ = "2.2"
|
||||
|
||||
# Supported Tendermint versions
|
||||
|
||||
@ -14,7 +14,7 @@ from planetmint.config import Config
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def make_error(status_code, message=None):
|
||||
def make_error(status_code, message=None, level: str = "debug"):
|
||||
if status_code == 404 and message is None:
|
||||
message = "Not found"
|
||||
|
||||
@ -22,6 +22,9 @@ def make_error(status_code, message=None):
|
||||
request_info = {"method": request.method, "path": request.path}
|
||||
request_info.update(response_content)
|
||||
|
||||
if level == "error":
|
||||
logger.error("HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s", request_info)
|
||||
else:
|
||||
logger.debug("HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s", request_info)
|
||||
|
||||
response = jsonify(response_content)
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
from flask import current_app
|
||||
from flask_restful import reqparse, Resource
|
||||
from planetmint.web.views import parameters
|
||||
from planetmint.web.views.base import make_error
|
||||
|
||||
|
||||
class OutputListApi(Resource):
|
||||
@ -23,5 +24,12 @@ class OutputListApi(Resource):
|
||||
|
||||
pool = current_app.config["bigchain_pool"]
|
||||
with pool() as planet:
|
||||
try:
|
||||
outputs = planet.get_outputs_filtered(args["public_key"], args["spent"])
|
||||
except Exception as e:
|
||||
return make_error(
|
||||
500,
|
||||
"Invalid output ({}): {} : {} - {}".format(type(e).__name__, e, args["public_key"], args["spent"]),
|
||||
level="error",
|
||||
)
|
||||
return [{"transaction_id": output.txid, "output_index": output.output} for output in outputs]
|
||||
|
||||
@ -73,7 +73,6 @@ class TransactionListApi(Resource):
|
||||
# `force` will try to format the body of the POST request even if the
|
||||
# `content-type` header is not set to `application/json`
|
||||
tx = request.get_json(force=True)
|
||||
|
||||
try:
|
||||
tx_obj = Transaction.from_dict(tx, False)
|
||||
except SchemaValidationError as e:
|
||||
@ -82,15 +81,21 @@ class TransactionListApi(Resource):
|
||||
message="Invalid transaction schema: {}".format(e.__cause__.message),
|
||||
)
|
||||
except KeyError as e:
|
||||
return make_error(400, "Invalid transaction ({}): {}".format(type(e).__name__, e))
|
||||
return make_error(400, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx))
|
||||
except ValidationError as e:
|
||||
return make_error(400, "Invalid transaction ({}): {}".format(type(e).__name__, e))
|
||||
return make_error(400, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx))
|
||||
except Exception as e:
|
||||
return make_error(500, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx), level="error")
|
||||
|
||||
with pool() as planet:
|
||||
try:
|
||||
planet.validate_transaction(tx_obj)
|
||||
except ValidationError as e:
|
||||
return make_error(400, "Invalid transaction ({}): {}".format(type(e).__name__, e))
|
||||
return make_error(400, "Invalid transaction ({}): {} :{}".format(type(e).__name__, e, tx))
|
||||
except Exception as e:
|
||||
return make_error(
|
||||
500, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx), level="error"
|
||||
)
|
||||
else:
|
||||
if tx_obj.version != Transaction.VERSION:
|
||||
return make_error(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user