title: Cannot return 404 error as json instead of html from a Flask-Restful app
body: <p>I am working on a simple Flask REST API test and when I call the {{url}}/items for example I get the items list. However if a call is passed to an endpoint that does not exist for example {{url}}/itemsss then I get the error 404 in html.</p>
  
  <p>I would like to make the error handling more friendly and return json instead of html for certain errors such as 400, 404,405...</p>
  
  <p>For the 404 for example i tried this:</p>
  
  <pre><code>@app.errorhandler(404)
  def not_found(e):
      response = jsonify({'status': 404,'error': 'not found',
                          'message': 'invalid resource URI'})
      response.status_code = 404
      return response
  </code></pre>
  
  <p>However it does not work.</p>
  
  <p>My issue is similar to this one: <a href="https://stackoverflow.com/questions/44618005/python-flask-both-json-and-html-404-error">Python Flask - Both json and html 404 error</a></p>
  
  <p>I wanted to know,  if using the blueprints the only way to accomplish this?</p>
  
  <p>If there a simpler way to output the 404 error as json?</p>
  
  <p>For example instead of this:</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt;
  
  &lt;title&gt;404 Not Found&lt;/title&gt;
  
  &lt;h1&gt;Not Found&lt;/h1&gt;
  
  &lt;p&gt;The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.&lt;/p&gt;
  </code></pre>
  
  <p>Something like this:</p>
  
  <pre><code>{
  
  error: true,
  
  status: 404,
  
  code: "error.notFound",
  
  message: "API endpoint not found",
  
  data: { }
  
  }
  </code></pre>
  
  <p>I appreciate your help with this.</p>