I have the following flask code –
except ValueError as e:
current_app.logger.error(e)
error_msg = {'message': 'Error provisioning!'}
return Response(
response=json.dumps(error_msg, indent=2),
status=400,
mimetype='application/json'
)
except Exception as e:
current_app.logger.error(e)
error_msg = {'message': 'Error provisioning!'}
return Response(
response=json.dumps(error_msg, indent=2),
status=500,
mimetype='application/json'
)
Whenever there is a valueError in my code I get the json error message in my response. But when there is any other exception, it enters the general exception block but it returns an empty response. It appears to be a problem with the 500 status code, because if I change status=500 to status=400, the error message is returned. Why is this happening?