I have a python flask app, pseudocode shown below.
@app.route('/predict', methods=['POST']) def transformation(): try: var1 = function_1() # do something with var1 var2 = function_2() except Exception as e: return jsonify({'message': '{}: {}'.format(type(e).__name__, e)}), 500 As you see, the POST call handler returns a generic exception message back to the client. But I want to customize those exception messages based on whether they are coming from function_1 or function_2
I looked into this thread and understand that it is possible to do below -
try: #something1 #something2 except ExceptionType1: #return xyz except ExceptionType2: #return abc But how would it know that ExceptionType1 is coming from function_1() or function_2(). How should I pass exception from function_1() or function_2() to be caught in the main try-except block?
raisea custom Exception for the route to catch.