Sha256: 6ab5d2514bcd3f0e735b9f37bcdc39c6eb9e9be9c08784db344fdb63a51f76f8
Contents?: true
Size: 1.48 KB
Versions: 34
Compression:
Stored size: 1.48 KB
Contents
module QuizApiClient module HttpRequest class Failure attr_reader :config def initialize(config) @config = config end def raise_error( method, url, response: nil, current_error: nil, error_class: QuizApiClient::HttpClient::RequestFailed ) context = generate_error_context(method, url, response) record_error_context(context) raise error_class.new(context), error_message(current_error, url, response) end private def generate_error_context(method, url, response = nil) context = { quiz_api_client: { request: { method: method, url: url } } } if response context[:quiz_api_client][:response] = { body: response.body, code: response.code } end context end def record_error_context(context) case config.error_handler when :sentry_raven require 'sentry-raven' Raven.extra_context(context) end end def error_message(current_error, url, response) if current_error && response "#{current_error.message}: #{url} responded #{response.body} (#{response.code})" elsif current_error current_error.message elsif response "#{url} responded #{response.body} (#{response.code})" end end end end end
Version data entries
34 entries across 34 versions & 1 rubygems