lib/etsy/response.rb in etsy-0.2.6 vs lib/etsy/response.rb in etsy-0.2.7

- old
+ new

@@ -1,15 +1,22 @@ module Etsy class OAuthTokenRevoked < StandardError; end class MissingShopID < StandardError; end - class EtsyJSONInvalid < StandardError; end class TemporaryIssue < StandardError; end class ResourceUnavailable < TemporaryIssue; end class ExceededRateLimit < TemporaryIssue; end class InvalidUserID < StandardError; end + class EtsyJSONInvalid < StandardError + attr_reader :code, :data + def initialize(args) + @code = args[:code] + @data = args[:data] + end + end + # = Response # # Basic wrapper around the Etsy JSON response data # class Response @@ -46,11 +53,11 @@ def result if success? results = to_hash['results'] || [] count == 1 ? results.first : results else - [] + Etsy.silent_errors ? [] : validate! end end # Total number of results of the request def total @@ -80,10 +87,10 @@ raise MissingShopID if missing_shop_id? raise InvalidUserID if invalid_user_id? raise TemporaryIssue if temporary_etsy_issue? raise ResourceUnavailable if resource_unavailable? raise ExceededRateLimit if exceeded_rate_limit? - raise EtsyJSONInvalid.new("CODE: #{code}, BODY: #{data}") unless valid_json? + raise EtsyJSONInvalid.new({:code => code, :data => data}) unless valid_json? true end def valid_json? json