lib/buckybox/api.rb in buckybox-api-1.2.1 vs lib/buckybox/api.rb in buckybox-api-1.3.0
- old
+ new
@@ -3,11 +3,12 @@
require "crazy_money"
require "super_recursive_open_struct"
module BuckyBox
class API
- ResponseError = Class.new(Exception)
+ ResponseError = Class.new(Exception) # generic error
+ NotFoundError = Class.new(Exception)
include HTTParty
format :json
base_uri "https://api.buckybox.com/v1"
@@ -65,11 +66,18 @@
def check_response!(response)
unless [200, 201].include? response.code
message = response.parsed_response["message"] || response.parsed_response
message = "Error #{response.code} - #{message}"
- raise ResponseError, message
+
+ raise exception_type(response.code), message
end
+ end
+
+ def exception_type(http_code)
+ {
+ 404 => NotFoundError,
+ }.fetch(http_code, ResponseError)
end
def query(type, uri, params = {}, options = {}, types = {})
options = {
as_object: true