Errors not showing in flask server
Consider the following minimal flask server
import rospy
from flask import Flask, request, Response, make_response
if __name__ == '__main__':
# Shutdown is handled by Flask
rospy.init_node("test", disable_signals=True)
app = Flask(__name__)
@App.errorhandler(Exception)
def server_error(error):
print(str(error))
rospy.logerror(error) # For some reason logerror doesn't work in errorhandler
return f"Error: {error}", 500
@App.route('/test', methods=['POST'])
def execute():
raise Exception("my error")
return Response(status=200, headers={})
rospy.loginfo("Starting server...")
app.run(host="127.0.0.1", port=50002)
When POSTing to 127.0.0.1:50002/test
, the following 2 lines are printed
my error
500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
It seems rospy.logerror
failed and caused another exception to be raised leading to the 500 Internal Server Error
. Why is this happening and how do I solve this?
PS:: Why is "@ app" converted to "@App" in the post? This doesn't happen in the preview.