Sha256: 51ffc700a7a11d99e4ab41709f92033cd8ae76eb2196060b75840fcaea4bf073
Contents?: true
Size: 758 Bytes
Versions: 3
Compression:
Stored size: 758 Bytes
Contents
# encoding: utf-8 module Outreach module Errors class Unauthorized < StandardError; end def check_for_error(status_code, response_body) response_hash = JSON.parse(response_body) if response_hash['errors'].present? && response_hash['errors']['status'].present? status_code = response_hash['errors']['status'] end # raise error if status code isn't 200 case status_code.to_i when 401 unauthorized_error(response_body) end end private def unauthorized_error(response_body) description = begin JSON.parse(response_body).fetch("error_description") rescue "Unauthorized" end raise Unauthorized.new(description) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
outreach-0.2.1 | lib/outreach/errors.rb |
outreach-0.2.0 | lib/outreach/errors.rb |
outreach-0.1.3 | lib/outreach/errors.rb |