1
votes

Stack: Ruby 2.2, Rails 4.2, and Honeybadger.

I've been working on the error handling code for my site. I've noticed that error handling has become a real mess though out the site, and I've been looking for a way to standardize error handling.

The following "generic" error types have been found:

  • Record/resource not found
  • Failure to save record
  • Validation issues
  • Rights/Permissions errors
  • Other (Usually probing bots, double clicks, or WTF?)

With the following resulting actions.

  • Notify Error Collating resource (maybe)
  • Save data; if a particularly long form input
  • Response: Redirect to an error page (flash[:error]='?')
  • Response: Return a JSON string (AJAX requests)
  • Response: Various Status codes http 3xx, 4xx, 5xx
  • Customized message for developer (maybe); quite lengthy in some cases
  • Customized message for user
  • Silently do nothing

And then process issues

  • Roll back
  • return (exiting the action; and not allowing further action)

Does anyone know of a Gem/Module/Tutorial that handles these collective issues holistically?

Thank you in advance!

-daniel

1
something like rubytutorial.io/rails-rescue_from or more specific? - scones
@scones rescue_from handles a specific issue, of throwing an exception. I had though of throwing an exception, but the matrix of (Why * Action) would mean making a lot of exceptions. - Daniel

1 Answers

0
votes

I think the best answer, is to throw an exception

Controller code is responsible for getting the parameters, sanitizing them, role/safety checks, making calls to GET data (this should be business logic), and the preparing the data for export back to the browser.

I'll add on to this handling exceptions from the code.

Then business logic, should throw an error should something fatalistic happen.