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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/kiev/rack/request_logger.rb', line 17
def call(env)
rescued_exception = nil
began_at = Time.now.to_f
request = ::Rack::Request.new(env)
begin
status, , body = @app.call(env)
rescue Exception => e
rescued_exception = e
status = ERROR_STATUS
= ERROR_HEADERS
body = ERROR_BODY
if defined?(ActionDispatch::ExceptionWrapper)
status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(rescued_exception.class.name)
end
end
response = ::Rack::Response.new(body, status, )
rack_exception = log_rack_exception?(env[SINATRA_ERROR]) ? env[SINATRA_ERROR] : nil
log_exception = RequestStore.store[:error]
exception = rescued_exception || rack_exception || log_exception
if exception || Config.instance.log_request_condition.call(request, response)
Kiev.event(
:request_finished,
form_data(
began_at: began_at,
env: env,
request: request,
response: response,
status: status,
body: body,
exception: exception
)
)
end
raise rescued_exception if rescued_exception
[status, , body]
end
|