Sha256: 5aae2b1421064c7c3b095a58e976c6acd850f3e7661c0be3c6af41d8cb453007

Contents?: true

Size: 687 Bytes

Versions: 5

Compression:

Stored size: 687 Bytes

Contents

module Lessonly
  class Exception < ::StandardError
    attr_accessor :cause

    def initialize(message, attrs = {})
      self.cause = attrs[:cause]
      super(message)
    end
  end

  class ResponseError < Exception
    attr_accessor :response
    attr_accessor :body

    def initialize(message, attrs = {})
      self.response = attrs[:response]
      self.body = attrs[:body]

      if body.present? && body.key?(:error)
        error = body[:error]
        message = "#{message} (#{error})"
      elsif response
        message = "#{message} (\"#{response.inspect}\")"
      end

      super(message, attrs)
    end
  end

  class ResourceNotFoundError < ResponseError; end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lessonly-ruby-0.1.3 lib/lessonly/exceptions.rb
lessonly-ruby-0.1.2 lib/lessonly/exceptions.rb
lessonly-ruby-0.1.1 lib/lessonly/exceptions.rb
lessonly-ruby-0.1.0 lib/lessonly/exceptions.rb
lessonly-ruby-0.0.1 lib/lessonly/exceptions.rb