title: Returning a response in Flask
body: <p>I have a code like this</p>
  
  <pre><code>def find_user(user_id):
      if not users.lookup(user_id):
          return jsonify(success=False, reason="not found")
      else:
          return users.lookup(user_id)
  
  @app.route(...)
  def view1(...):
      user = find_user(...)
      if user:
         do_something
      return jsonify(success=True, ....)
  </code></pre>
  
  <p>The point is I have a helper function and if <code>condition</code> is met I want to return the response right away. In this case if user is not found, I want to return a request stating the request failed and give a reason.</p>
  
  <p>The problem is because the function can also return some other values (say a user object) . 
  I will not return from the request. Instead, because we got an assignment we will continue with the rest of the code path.</p>
  
  <p>I probably can do a type check but that's ugly!</p>
  
  <p>Ideally this is the longer code</p>
  
  <pre><code>def view(...)
      user = users.lookup(user_id)
      if not user:
         return jsonify(success=False....)
      # if user is true, do something else
  </code></pre>
  
  <p>The whole point of the helper function <code>find_user</code> is to extract out common code and then reuse in a few other similar apis.</p>
  
  <p>Is there a way to return the response directly in my current code? It seems like this is a deadend... unless I change how the code is written (how values are returned...)</p>