fluyenta-ruby 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5fab76eeb7fe5e7336aafff67123c751df4fc149649b886a1606bbdb75135832
|
|
4
|
+
data.tar.gz: 05a8e5ec3449ffb2f22720fcae790a2b503213d5990ebd6fcb5d348f51f7d6df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70c448c6019272169c8eef9c4b469381cb7dfcc401aa85c5a3b6e9b85986a8f00470418bf40f92d040b05cdc9730b97f8fde5bce46970e5e58fecaae0ebc916a
|
|
7
|
+
data.tar.gz: dda6842f5584f20309c6a8ab86ba0ee7462609a2884570fdc43c11bd16e79e44b2a086111d9d8584d9e96eca21ffde370260bbeecda548f74180506f9b889ca6
|
|
@@ -38,6 +38,7 @@ module BrainzLab
|
|
|
38
38
|
return false unless DevTools.debug_panel_enabled?
|
|
39
39
|
return false unless DevTools.allowed_environment?
|
|
40
40
|
return false unless DevTools.allowed_ip?(extract_ip(env))
|
|
41
|
+
return false if env['REQUEST_METHOD'] == 'OPTIONS'
|
|
41
42
|
return false if asset_request?(env['PATH_INFO'])
|
|
42
43
|
return false if devtools_asset_request?(env['PATH_INFO'])
|
|
43
44
|
return false if turbo_stream_request?(env)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
3
5
|
module BrainzLab
|
|
4
6
|
module DevTools
|
|
5
7
|
module Middleware
|
|
@@ -10,29 +12,33 @@ module BrainzLab
|
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def call(env)
|
|
15
|
+
return @app.call(env) if env['REQUEST_METHOD'] == 'OPTIONS'
|
|
13
16
|
return @app.call(env) unless should_handle?(env)
|
|
14
17
|
|
|
15
18
|
begin
|
|
16
19
|
status, headers, body = @app.call(env)
|
|
17
20
|
|
|
18
21
|
# Check if this is an error response that we should intercept
|
|
19
|
-
if status >= 400 && html_response?(headers) && !json_request?(env)
|
|
22
|
+
if status >= 400 && html_response?(headers) && !json_request?(env) && !api_path?(env)
|
|
20
23
|
# Check if this looks like Rails' default error page
|
|
21
24
|
body_content = collect_body(body)
|
|
22
25
|
if body_content.include?('Action Controller: Exception caught') || body_content.include?('background: #C00')
|
|
23
26
|
# Extract exception info from the page
|
|
24
27
|
exception_info = extract_exception_from_html(body_content)
|
|
25
28
|
if exception_info
|
|
26
|
-
data = collect_debug_data_from_info(env, exception_info)
|
|
27
|
-
return render_error_page_from_info(exception_info, data)
|
|
29
|
+
data = collect_debug_data_from_info(env, exception_info, status)
|
|
30
|
+
return render_error_page_from_info(exception_info, data, status)
|
|
28
31
|
end
|
|
29
32
|
end
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
[status, headers, body]
|
|
33
36
|
rescue Exception => e
|
|
34
|
-
#
|
|
35
|
-
|
|
37
|
+
# For JSON/API requests, return a proper JSON error response
|
|
38
|
+
if json_request?(env) || api_path?(env)
|
|
39
|
+
capture_to_reflex(e)
|
|
40
|
+
return json_error_response(e)
|
|
41
|
+
end
|
|
36
42
|
|
|
37
43
|
# Still capture to Reflex if available
|
|
38
44
|
capture_to_reflex(e)
|
|
@@ -87,7 +93,7 @@ module BrainzLab
|
|
|
87
93
|
.gsub(' ', ' ')
|
|
88
94
|
end
|
|
89
95
|
|
|
90
|
-
def collect_debug_data_from_info(env, info)
|
|
96
|
+
def collect_debug_data_from_info(env, info, status = 500)
|
|
91
97
|
context = defined?(BrainzLab::Context) ? BrainzLab::Context.current : nil
|
|
92
98
|
collector_data = Data::Collector.get_request_data
|
|
93
99
|
|
|
@@ -113,7 +119,7 @@ module BrainzLab
|
|
|
113
119
|
}
|
|
114
120
|
end
|
|
115
121
|
|
|
116
|
-
def render_error_page_from_info(info, data)
|
|
122
|
+
def render_error_page_from_info(info, data, status = 500)
|
|
117
123
|
# Create a simple exception-like object
|
|
118
124
|
exception = StandardError.new(info[:message])
|
|
119
125
|
exception.define_singleton_method(:class) do
|
|
@@ -126,7 +132,7 @@ module BrainzLab
|
|
|
126
132
|
html = @renderer.render(exception, data)
|
|
127
133
|
|
|
128
134
|
[
|
|
129
|
-
|
|
135
|
+
status,
|
|
130
136
|
{
|
|
131
137
|
'Content-Type' => 'text/html; charset=utf-8',
|
|
132
138
|
'Content-Length' => html.bytesize.to_s,
|
|
@@ -169,6 +175,48 @@ module BrainzLab
|
|
|
169
175
|
env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
|
|
170
176
|
end
|
|
171
177
|
|
|
178
|
+
def api_path?(env)
|
|
179
|
+
path = env['PATH_INFO'] || ''
|
|
180
|
+
path.start_with?('/api/')
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def exception_to_status(exception)
|
|
184
|
+
case exception.class.name
|
|
185
|
+
when 'ActionController::RoutingError', 'AbstractController::ActionNotFound'
|
|
186
|
+
404
|
|
187
|
+
when 'ActionController::MethodNotAllowed'
|
|
188
|
+
405
|
|
189
|
+
when 'ActionController::BadRequest', 'ActionDispatch::Http::Parameters::ParseError'
|
|
190
|
+
400
|
|
191
|
+
when 'ActionController::UnknownFormat'
|
|
192
|
+
406
|
|
193
|
+
else
|
|
194
|
+
500
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def json_error_response(exception)
|
|
199
|
+
status_code = exception_to_status(exception)
|
|
200
|
+
message = case status_code
|
|
201
|
+
when 400 then 'Bad request'
|
|
202
|
+
when 404 then 'Not found'
|
|
203
|
+
when 405 then 'Method not allowed'
|
|
204
|
+
when 406 then 'Not acceptable'
|
|
205
|
+
else 'Internal server error'
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
body = JSON.generate({ error: message })
|
|
209
|
+
[
|
|
210
|
+
status_code,
|
|
211
|
+
{
|
|
212
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
|
213
|
+
'Content-Length' => body.bytesize.to_s,
|
|
214
|
+
'X-Content-Type-Options' => 'nosniff'
|
|
215
|
+
},
|
|
216
|
+
[body]
|
|
217
|
+
]
|
|
218
|
+
end
|
|
219
|
+
|
|
172
220
|
def capture_to_reflex(exception)
|
|
173
221
|
return unless defined?(BrainzLab::Reflex)
|
|
174
222
|
|
|
@@ -223,7 +223,11 @@ module BrainzLab
|
|
|
223
223
|
context.request_method = request.request_method
|
|
224
224
|
context.request_path = request.path
|
|
225
225
|
context.request_url = request.url
|
|
226
|
-
context.request_params =
|
|
226
|
+
context.request_params = begin
|
|
227
|
+
filter_params(request.params.to_h)
|
|
228
|
+
rescue ActionDispatch::Http::Parameters::ParseError
|
|
229
|
+
{}
|
|
230
|
+
end
|
|
227
231
|
context.request_headers = extract_headers(env)
|
|
228
232
|
|
|
229
233
|
# Add breadcrumb for request start
|
data/lib/brainzlab/version.rb
CHANGED