|
|
@@ -1,5 +1,8 @@
|
|
|
+import grp
|
|
|
from flask import Flask, request, jsonify
|
|
|
from json import JSONEncoder
|
|
|
+import json
|
|
|
+import grpc
|
|
|
|
|
|
# Here are Iroha dependencies.
|
|
|
# Python library generally consists of 3 parts:
|
|
|
@@ -9,6 +12,7 @@ import binascii
|
|
|
from iroha import IrohaCrypto
|
|
|
from iroha import Iroha, IrohaGrpc
|
|
|
from werkzeug.wrappers import response
|
|
|
+from werkzeug.exceptions import HTTPException
|
|
|
|
|
|
# Here is the information about the environment and admin account information:
|
|
|
IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', '127.0.0.1')
|
|
|
@@ -65,6 +69,21 @@ transferAssetsValidationErrors = [
|
|
|
StatefulValidationError("Too long description", "Too long description", "Ensure that description length matches the criteria above (or just shorten it)")
|
|
|
]
|
|
|
|
|
|
+@app.errorhandler(Exception)
|
|
|
+def handle_exception(e):
|
|
|
+ # pass through HTTP errors
|
|
|
+ if isinstance(e, HTTPException):
|
|
|
+ return e
|
|
|
+
|
|
|
+ if isinstance(e, grpc.RpcError):
|
|
|
+ return {
|
|
|
+ "details" : e.details(),
|
|
|
+ "debug_error" : json.loads(e.debug_error_string())
|
|
|
+ }, 500
|
|
|
+
|
|
|
+ # now you're handling non-HTTP exceptions only
|
|
|
+ return e, 500
|
|
|
+
|
|
|
@app.route("/", methods=['GET'])
|
|
|
def Hello():
|
|
|
return "IROHA REST API"
|