Sha256: cbf232d868a15232429f8258a4c9635920e3f64332bcbbfcbefd28806c8e47cc

Contents?: true

Size: 970 Bytes

Versions: 1

Compression:

Stored size: 970 Bytes

Contents

require 'json'

module Avski
  module Common
    module Exceptions

      # @class [UnknownFieldException]
      class UnknownFieldException < StandardError
        attr_reader :status, :message, :data, :code

        def initialize(message, status = 400, code = 0, data = {})
          @status = status
          @message = message
          @data = data
          @code = code
        end

        #
        # Convert Exception contents to a Json string. All attributes must
        # be Json serializable.
        def to_json
          JSON.generate(to_hash)
        end

        def to_hash
          {status: @status, message: @message, code: @code, data: @data}
        end

        def to_response
          [@status, to_json]
        end
      end

      # @class [EmptyFieldException]
      class EmptyFieldException < UnknownFieldException; end

      # @class [NullFieldException]
      class NullFieldException < UnknownFieldException; end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
avski-common-utils-0.1.4 lib/avski/common/exceptions.rb