title: What exactly does flask.abort() do?
body: <p>I'm actually working with flask. 
  I use flask in order to run a server, which will be requested by a chrome extension (js).</p>
  
  <p>Requesting the server from the extension  is quite simple : I use the <a href="https://developer.chrome.com/extensions/runtime#method-sendMessage" rel="noreferrer">chrome.runtime.sendMessage()</a> method. This method provides also a callback function, taking as parameters a JSON object (the response from the server).</p>
  
  <p>E.g, suppose that I have this route on my server :</p>
  
  <pre><code>@app.route('/users', methods=['POST'])
      def api_login():
          if 'username' not in request.json :
              return jsonify(success=false)
          else :
              return jsonify(success=true)
  </code></pre>
  
  <p>Then, I can in my extenstion, and more precisely in the callback function, check the success value : </p>
  
  <pre><code>function(response) {
      if(response.success){
          console.log("Login ok !")
      }
  }
  </code></pre>
  
  <p>But now, my team doesn't want rely on this anymore, and wants to use http error code instead. I know that flask has an abort function, but while reading the documentation, I have had a lot of trouble to understand what it really does. When I call in my route :</p>
  
  <pre><code>else:
      abort(422, {"error":"Missing parameters"})
  </code></pre>
  
  <p>how can I use these information on the extension (js) ? Does flask automatically returns a specific JSON object when abort is called ? How can I check the error code ? I would like to do something like that in the client code :</p>
  
  <pre><code>if(response.status == 422) {
      console.log("Error")
  }
  </code></pre>
  
  <p>One of the clues I have, reading all the StackOverflow threads about abort() is to define a specific error function using the decorator @app.errorhandler(code) :</p>
  
  <pre><code>@app.errorhandler(422)
  def myErrorCase(error):
      return jsonify(status=422, error="missing parameters")
  </code></pre>
  
  <p>But I assume that there are more straightforward ways.</p>
  
  <p>Thanks for your help.</p>