Sha256: d067b8717d00021bab43f908159f350126a1f3ff17a8974c99b4e6798e0c32c0

Contents?: true

Size: 605 Bytes

Versions: 1

Compression:

Stored size: 605 Bytes

Contents

module RDStation
  class ErrorHandler
    class Unauthorized
      attr_reader :api_response, :response_body, :error

      ERROR_CODE = 'UNAUTHORIZED'.freeze
      EXCEPTION_CLASS = RDStation::Error::Unauthorized

      def initialize(api_response)
        @api_response = api_response
        @error = JSON.parse(api_response.body)['errors']
      end

      def raise_error
        return unless unauthorized?
        raise EXCEPTION_CLASS.new(error['error_message'], api_response)
      end

      private

      def unauthorized?
        error['error_type'] == ERROR_CODE
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rdstation-ruby-client-1.0.0 lib/rdstation/error_handler/unauthorized.rb