-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Stream Rails error pages #173
Conversation
Co-Authored-By: Mikael Henriksson <[email protected]>
8037594
to
13b9825
Compare
lib/phlex/rails/streaming.rb
Outdated
@@ -17,10 +17,29 @@ def stream(view) | |||
self.response_body = Enumerator.new do |buffer| | |||
view.call(buffer, view_context: view_context) | |||
rescue => e | |||
buffer << %('">) | |||
buffer << view_context.javascript_tag(nonce: true) { %(window.location = "/500.html").html_safe } | |||
raise (e) if Rails.env.test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In test environments, I think we want to just raise.
lib/phlex/rails/streaming.rb
Outdated
debug_middleware = ActionDispatch::DebugExceptions.new( | ||
proc { |env| raise(e) }, | ||
response_format: :html | ||
) | ||
|
||
_debug_status, _debug_headers, debug_body = debug_middleware.call(request.env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can call the ActionDispatch::DebugExceptions
middleware to get the debug page HTML, which we can send via JavaScript to the streaming client.
|
||
if Rails.env.development? | ||
js = <<~JAVASCRIPT | ||
document.documentElement.innerHTML = "#{view_context.j(debug_body.join)}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In development, we send some JS that replaces the document with the debug body, so you get nice error pages.
buffer << %(-->"'>) | ||
buffer << view_context.javascript_tag(js, nonce: true) | ||
|
||
p e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems left over from local testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it’s so you can see the error in the console. We can probably improve this somewhat, but we should have some useful output in the console as well as the page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can’t use raise
it again, because it blocks the request. Unless there’s some way to manually tell ActionDispatch to close the request.
lib/phlex/rails/streaming.rb
Outdated
|
||
// Re-evaluate all script tags | ||
document.querySelectorAll("script").forEach((script) => { | ||
newScript = document.createElement("script"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awfully familiar!!
Signed-off-by: Joel Drapper <[email protected]>
No description provided.