mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
8cbc19d86b
Fix: https://github.com/rails/rails/issues/43472 The reporter is held by the executor, but the `Rails` module provides a nicer `Rails.error` shortcut. For ease of use, two block based specialized methods are exposed. `handle`, which swallow errors and forward them to the subscribers: ```ruby Rails.error.handle do 1 + '1' # raises TypeError end 1 + 1 # This will be executed ``` `record`, which forward the errors to the subscribes but let it continue rewinding the call stack: ```ruby Rails.error.record do 1 + '1' # raises TypeError end 1 + 1 # This won't be executed. ``` For cases where the blocked based API isn't suitable, the lower level `report` method can be used: ```ruby Rails.error.report(error, handled: true / false) ```
24 lines
538 B
Ruby
24 lines
538 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "rack/body_proxy"
|
|
|
|
module ActionDispatch
|
|
class Executor
|
|
def initialize(app, executor)
|
|
@app, @executor = app, executor
|
|
end
|
|
|
|
def call(env)
|
|
state = @executor.run!
|
|
begin
|
|
response = @app.call(env)
|
|
returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
|
|
rescue => error
|
|
@executor.error_reporter.report(error, handled: false)
|
|
raise
|
|
ensure
|
|
state.complete! unless returned
|
|
end
|
|
end
|
|
end
|
|
end
|