Comments (7)
I'll take a crack at this. Might be a few days as I'm in and out of internet.
from hanami.
We can inspire here - https://github.com/hassox/rack-rescue/blob/master/lib/rack/rescue.rb for production and I think we can add https://github.com/charliesome/better_errors into default generated app Gemfile (and make it optionable in generator). I don't see any reason why we should duplicate better_errors code.
from hanami.
@simi The scope of this ticket is to allow to customize production error pages.
While better_errors
is for development purposes. Because Lotus depends on Rack, we already have Rack::ShowExceptions
as an alternative.
from hanami.
So plan is to add custom configurable rack middleware to production middleware stack to handle errors?
from hanami.
@simi Where did you read that? Rack::ShowExceptions
is for development as well, and it's out of scope here.
Right now we have the scenario depicted in the description of this ticket.
The idea is to let developers to add a file like apps/bookshelf/templates/500.html.erb
, where they can define the production error page.
from hanami.
Reporting here an idea of for implementation, that I had in a discussion with @twe4ked .
If you look at the signature of a view's constructor it's: #initialize(template, locals)
. Lotus::View.render
is also a factory: it instantiate a view, passing the right template.
What if we override it?
def self.render(root, template_name, context)
if template = DefaultTemplateFinder.new(root, template_name).find
new(template, context).render # the developer has defined a custom template
else
super(context) # render the default view
end
end
..and
class Lotus::Views::DefaultTemplateFinder < Lotus::View::Rendering::TemplateFinder
def initialize(root, template_name)
@root = root
@options = { template_name: template_name }
end
private
def root
@root
end
end
.. to be used like:
# lib/lotus/rendering_policy.rb
Lotus::Views::Default.render(@templates, response.code, {response: response, format: :html})
from hanami.
I got this working but never had time to finish the tests. I'll try get to it soon but if anyone else gets to it first that's fine. Sorry it's taken so long. I assume we would want integration tests for this? I created a PR (#61) of what I've got so far.
from hanami.
Related Issues (20)
- Router - can i configure such that routing is matched with or without ending "/". HOT 1
- Can't use middleware in scope HOT 1
- Routes error when launching one specific slice, could be done automatically?
- rack app is being re-initialised for every request
- Trouble loading & using dry-monads with Hanami 2.1 beta HOT 5
- Track Hanami 2.2 progress here
- Not found route returns 500 instead of 404 HOT 1
- Implement static assets Rack middleware HOT 1
- Reintroduce Rake task for assets
- Handled errors should not log as errors
- Revisit config/puma.rb, and fix preloading issue
- Test with React and Tailwind HOT 3
- Use rack method override middleware by default
- Isolate assets in view parts to a `helpers` object
- Roll back all "short names" for asset helpers (image, video, favicon, js, javascript, css, stylesheet)
- Render new welcome view as the starter route HOT 1
- Fix use of helpers within parts HOT 7
- guard required? HOT 1
- Could not find gem 'hanami-router (~> 2.1.0.rc)' HOT 12
- 2.1 RC1 - bundler: command not found: hanami on Heroku deploy HOT 22
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hanami.