module Vonage::Errors
Public Class Methods
parse(response)
click to toggle source
# File lib/vonage/errors.rb, line 10 def self.parse(response) exception_class = case response when Net::HTTPUnauthorized AuthenticationError when Net::HTTPClientError ClientError when Net::HTTPServerError ServerError else Error end message = if response.content_type == 'application/json' hash = ::JSON.parse(response.body) if hash.key?('error_title') hash['error_title'] elsif hash.key?('error-code-label') hash['error-code-label'] elsif hash.key?('description') hash['description'] elsif problem_details?(hash) problem_details_message(hash) end end exception_class.new(message) end
problem_details?(hash)
click to toggle source
# File lib/vonage/errors.rb, line 40 def self.problem_details?(hash) hash.key?('title') && hash.key?('detail') && hash.key?('type') end
problem_details_message(hash)
click to toggle source
# File lib/vonage/errors.rb, line 45 def self.problem_details_message(hash) "#{hash['title']}. #{hash['detail']} See #{hash['type']} for more info, or email support@nexmo.com if you have any questions." end