11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/immunio/plugins/exception_handler.rb', line 11
def call(env)
@app.call(env)
rescue RequestBlocked
Request.time "plugin", "#{Module.nesting[0]}::#{__method__}[RequestBlocked]" do
Immunio.blocked_app.call(env)
end
rescue OverrideResponse => override
status, , body = Immunio.override_response.call(env, override)
Immunio.run_hook "http_tracker", "http_response_start",
status: status, headers:
[status, , body]
rescue StandardError => e
Request.time "plugin", "#{Module.nesting[0]}::#{__method__}[#{e.class}]" do
original_exception = unwrap_exception(e)
if RequestBlocked === original_exception || original_exception.message =~ /^Immunio::RequestBlocked:/
return Immunio.blocked_app.call(env)
end
if OverrideResponse === original_exception status, , body = Immunio.override_response.call(env, original_exception)
Immunio.run_hook "http_tracker", "http_response_start",
status: status, headers:
return [status, , body]
end
Immunio.run_hook! "exception_handler", "exception", exception: "#{e.class.name}: #{e}"
raise
end
end
|