Module: SentryTopErrors::ApiResponse
- Defined in:
- lib/sentry_top_errors/api_response.rb
Defined Under Namespace
Modules: ExtMethods Classes: FromArray, FromHash
Class Method Summary collapse
Class Method Details
.new_from_res(http_res) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sentry_top_errors/api_response.rb', line 2 def self.new_from_res(http_res) if http_res.status == 429 || http_res.status >= 500 raise "Failed response #{http_res.status} - #{http_res.body}" end new_obj = begin if http_res.body.start_with?('[') && http_res.body.end_with?(']') SentryTopErrors::ApiResponse::FromArray.new.concat(JSON.parse(http_res.body)) else SentryTopErrors::ApiResponse::FromHash.new().merge!(JSON.parse(http_res.body)) end rescue JSON::ParserError => error puts "Failed to parse response #{http_res.body}" end new_obj.response = http_res new_obj end |