module Bigcommerce::HttpErrors

Constants

ERRORS

Public Instance Methods

throw_http_exception!(code, env) click to toggle source
# File lib/bigcommerce/exception.rb, line 42
def throw_http_exception!(code, env)
  return unless ERRORS.keys.include? code
  response_headers = {}
  unless env.body.empty?
    response_headers = begin
      JSON.parse(env.body, symbolize_names: true)
    rescue StandardError
      {}
    end
  end
  unless env[:response_headers] && env[:response_headers]['X-Retry-After'].nil?
    response_headers[:retry_after] = env[:response_headers]['X-Retry-After'].to_i
  end
  raise ERRORS[code].new(response_headers), env.body
end