Sha256: 50240898a9b40aca8665be23a5771523b1fde4230754cc79a4778ba14559a496

Contents?: true

Size: 783 Bytes

Versions: 4

Compression:

Stored size: 783 Bytes

Contents

module Workarea
  module Listrak
    class Error < StandardError; end

    class OauthError < Listrak::Error
      attr_reader :http_response

      def initialize(http_response)
        @http_response = http_response
        super(http_response.body)
      end

      def body
        @body ||= JSON.parse(http_response.body) rescue nil
      end
    end

    class HttpError < StandardError
      attr_reader :http_response

      def initialize(http_response)
        @http_response = http_response
        super(http_response.body)
      end

      def body
        @body ||= JSON.parse(http_response.body) rescue nil
      end

      def error_code
        body["error"] rescue nil
      end

      def api_message
        body["message"] rescue nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
workarea-listrak-5.0.4 lib/workarea/listrak/error.rb
workarea-listrak-5.0.3 lib/workarea/listrak/error.rb
workarea-listrak-5.0.2 lib/workarea/listrak/error.rb
workarea-listrak-5.0.1 lib/workarea/listrak/error.rb