Sha256: a6fbf69217f33996a105ac54ecdabf54d69bdefededc09593343adfaba0ee54c

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

module Quaderno
  module Exceptions
    class InvalidSubdomainOrToken < Exception
    end

    class InvalidID < Exception
    end

    class RateLimitExceeded < Exception
    end

    class HasAssociatedDocuments < Exception
    end

    class RequiredFieldsEmptyOrInvalid < Exception
    end

    class ThrottleLimitExceeded < Exception
    end

    def self.included(receiver)
      receiver.send :extend, ClassMethods
    end  

    module ClassMethods
      def check_exception_for(party_response, params = {})
        if params[:throttle_limit].nil? == false
         raise(Quaderno::Exceptions::ThrottleLimitExceeded, 'Throttle limit exceeded, please try again later') if party_response.response.class == Net::HTTPServiceUnavailable 
        end
        if params[:rate_limit].nil? == false
          raise(Quaderno::Exceptions::RateLimitExceeded, 'Rate limit exceeded') if party_response.response.class == Net::HTTPForbidden
        end
        if params[:subdomain_or_token].nil? == false
          raise(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token') if party_response.response.class == Net::HTTPUnauthorized
        end
        if params[:id].nil? == false
          raise(Quaderno::Exceptions::InvalidID, "Invalid #{ api_model } instance identifier") if (party_response.response.class == Net::HTTPInternalServerError) || (party_response.response.class == Net::HTTPNotFound)
        end
        if params[:required_fields].nil? == false
          raise(Quaderno::Exceptions::RequiredFieldsEmpty, "#{ JSON::parse party_response.body }") if party_response.response.class == Net::HTTPUnprocessableEntity
        end
        if params[:has_documents].nil? == false
          raise(Quaderno::Exceptions::HasAssociatedDocuments, "#{ JSON::parse party_response.body }") if party_response.response.class == Net::HTTPClientError 
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
quaderno-1.6.1 lib/quaderno-ruby/exceptions/exceptions.rb
quaderno-1.5.5 lib/quaderno-ruby/exceptions/exceptions.rb
quaderno-1.5.4 lib/quaderno-ruby/exceptions/exceptions.rb