Sha256: 10e3b02b93f5fff63227927b247ecd61bbd270d29cf133a30aa70a15e7d6b20f

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

Contents

module Finix

  class ResourceErrors < ::StandardError
    attr_reader :response
    attr_reader :errors

    def initialize(response=nil)
      @response = response
      @errors = []
      @response[:body]['_embedded']['errors'].each { |error| @errors.push Finix::ResourceError.new error}
    end

    def to_s
      "#{@errors}"
    end

    def inspect
      to_s
    end
  end

  class ResourceError < ::StandardError
    attr_reader :attributes

    def initialize(error = {})
      @attributes = {}
      @attributes = @attributes.merge error
    end

    def to_s
      "#{self.class.name.split('::').last || ''} #{@attributes}"
    end

    def inspect
      to_s
    end
  end

  class BadRequest < ResourceErrors; end
  class Unauthorized < ResourceErrors; end
  class Forbidden < ResourceErrors; end
  class NotFound < ResourceErrors; end
  class MethodNotAllowed < ResourceErrors; end
  class UnprocessableEntity < ResourceErrors; end
  class ServerError < ResourceErrors; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
finix-0.11 lib/finix/error.rb