title: Restful Web Service Error Handling
body: <p>In my <code>API</code>, when creating a new user, I call a number of functions:</p>
  
  <pre><code>userInfo = request.get_json()           
  email = userInfo.get('email')       
  password = userInfo.get('password')
  validate_email(email)       
  validate_password(password)     
  
  if (no_errors):
      add_user_to_database(user)
  else:
      return exception(?)
  </code></pre>
  
  <p>My goal is that I want to collect any and all errors that arise from the result of any of the first 3 <code>function</code> calls. It is possible that one function may catch more than one error.</p>
  
  <p>Eg:</p>
  
  <pre><code>def validate_email(email):
      if email is None:
          # store error
      else:
          if email_already_on_server(email)
             # store error
          if email_too_long(email)
             # store error
  
      # What should I be doing here..
  </code></pre>
  
  <p>After I have all my <code>errors</code> stored, I want to return an <code>exception(?)</code> displaying all the <code>errors</code> that were picked up.</p>
  
  <p>I'm not sure what the best way to do this is.. </p>
  
  <p>1) Should I create a single object (a custom error class) to pass to all my functions to store any <code>errors</code>?</p>
  
  <p>2) If errors are found, what should I return to the user? Would it be a custom <code>exception</code>, with a <code>HTTP status code</code> also containing all the errors in a <code>JSON</code> format?</p>
  
  <p>I'm having a tough time getting my head around the proper way to do this.</p>