title: API in Flask--returns JSON but HTML exceptions break my JSON client
body: <p>exceptions returned in HTML break my JSON client. I want to jsonify this output.</p>
  
  <p>More detail: i have a view function which an endpoint of this api app.</p>
  
  <p>As you can see, this function returns the result in json.  </p>
  
  <pre><code>@app.route('/route1')
  def api_route1():
      if user_id in request.args: 
          k1 = request.args['user_id']
          return flask.jsonify(recs=some_function(k1))
      else:
          return "no valid user_id supplied"
  </code></pre>
  
  <p>The problem, unhandled exception are in HTML, e.g.,</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 
      Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;TypeError: 'NoneType' object is not iterable // Werkzeug Debugger&lt;/title&gt;
          &lt;link rel="stylesheet" 
              href="?__debugger__=yes&amp;amp;cmd=resource&amp;amp;f=style.css" 
              type="text/css"&gt;
  </code></pre>
  
  <p>This breaks my json client. The HTML format is clearly a default, but i don't know how to opt out of it and specify jsonified exceptions (and ideally jsonify anything returned even headers).</p>
  
  <p>I suspect what i need is somewhere in the excellent Flask documentation, but i can't find it.</p>