Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error pages dynamic and customizable #26

Closed
sheerun opened this issue Aug 16, 2013 · 3 comments
Closed

Make error pages dynamic and customizable #26

sheerun opened this issue Aug 16, 2013 · 3 comments

Comments

@sheerun
Copy link
Owner

sheerun commented Aug 16, 2013

http://railscasts.com/episodes/53-handling-exceptions-revised

Reasoning

  • Almost every Rails app I know leaves default error pages, which is a shame.
  • In my experience when it comes to implementing custom error pages they are written in plain html and put in public, and after that completely forgotten, differing more and more from layout design.
  • For 500 API calls, the public/500.html is rendered by default. What should render is JSON with error message.

The solution is to define explicit controller for handling exceptions. That way you can use site layout template, SLIM, rails helpers etc. In general error pages become more dynamic.

Possible downsides

Error handling deadloop (error is thrown from error controller). I'll try to implement some safeguard for this case though. I think of fallback to public/500.html when there is an exception thrown in errors controller.

Also, to prevent such cases I think ExceptionsController should inherit directly from ActionController::Base, instead of ApplicationController. That should protect it from programming errors committed in ApplicationController.

@sheerun
Copy link
Owner Author

sheerun commented Aug 18, 2013

For not I cannot find any gem for it. The solution is easy enough to be implemented directly imho.

sheerun added a commit that referenced this issue Aug 18, 2013
@sheerun
Copy link
Owner Author

sheerun commented Aug 18, 2013

Final decisions

  • Error pages in /public removed all together
  • It turned out Rails 4 has safeguard against dead-loops in exceptions_app
  • Error pages look just like Rails' defaults, but implemented using layout and templates
  • Applications searches for error template in errors/500.slim or similar, and fallbacks to errors/show.slim
  • The rest is implemented just as on RailsCast

@sheerun
Copy link
Owner Author

sheerun commented Oct 16, 2013

Tested for interoperation with Sentry (Raven) and error logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant