Sha256: 788c81c2bf74c89decff82e21c27a1fa42db68c017021b98b721f72182aa0c3a

Contents?: true

Size: 567 Bytes

Versions: 5

Compression:

Stored size: 567 Bytes

Contents

module BlockScore
  module Response
    extend self

    def handle_response(resource, response)
      case response.code
      when 200, 201
        Dispatch.new(resource, response).call
      else
        api_error(response)
      end
    end

    private

    def api_error(response)
      case response.code
      when 400
        fail InvalidRequestError.new(response)
      when 401
        fail AuthenticationError.new(response)
      when 404
        fail NotFoundError.new(response)
      else
        fail APIError.new(response)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
blockscore-4.2.1 lib/blockscore/response.rb
blockscore-4.2.0 lib/blockscore/response.rb
blockscore-4.1.2 lib/blockscore/response.rb
blockscore-4.1.1 lib/blockscore/response.rb
blockscore-4.1.0 lib/blockscore/response.rb