Returning API Error Messages with Python and Flask Returning API Error Messages with Python and Flask python python

Returning API Error Messages with Python and Flask


You could use abort(http_code) to return an appropriate http code to the client or just raise a non-http exception. And use @app.errorhandler() decorator to provide a custom handler for http errors and arbitrary exceptions. You could also use an ordinary try/except block where you are ready to handle an exception. Python is not Go you can use exceptions.


Maybe the Flask API is more suitable for your needs, as it is particularly designed for RESTful APIs.

It has better exception handling than Flask, see: http://www.flaskapi.org/api-guide/exceptions/