title: Handling API and UI errors in flask application
body: <p>I'm working on a Flask app that will serve as my website and my API.</p>
  <p>For example, all routes which have the <code>/api/*</code> pattern are in the API category and other routes are for my website.</p>
  <p>Since all API routes return a <code>jsonify</code> as a result and the website is a graphical user interface, I want to handle errors in the proper way.
  I mean if they are calling an API and it ends in an exception I want to exception return a <code>jsonify</code> for the error handling and if they are on my website the error should be returned as a rendered HTML.</p>
  <p>I'm open to any suggestion on how to implement this except the following answer:</p>
  <pre><code>Using another IP, domain, port or etc...
  </code></pre>
  <p>Edit: I like to use the following code</p>
  <pre class="lang-py prettyprint-override"><code>@app.errorhandler(exceptions.HTTPException)
  def error(exception: exceptions.HTTPException):
      * magic *
  </code></pre>