2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/qrapi/error_handling_resourceable.rb', line 2
def self.included(base)
base.send(:resources) do
default_handler do |response|
if (200...299).include?(response.status)
next
elsif response.status == 429
error = QRAPI::RateLimitReached.new("#{response.status}: #{response.body}")
error.limit = response.["RateLimit-Limit"]
error.remaining = response.["RateLimit-Remaining"]
error.reset_at = response.["RateLimit-Reset"]
raise error
else
body = JSON.parse(response.body)
error_message = body["meta"]["error"]["errorMessage"]
error_code = body["meta"]["error"]["errorCode"]
raise QRAPI::Error.new("Status: #{response.status} Error: #{error_code} - #{error_message}")
end
end
end
end
|