Sha256: 898da181495d5ea7b73bdafb89df6d1fd30bfbcea02a91024373f46b97a55ae3

Contents?: true

Size: 665 Bytes

Versions: 8

Compression:

Stored size: 665 Bytes

Contents

module TextMagic

  class API

    class Error < StandardError

      attr_reader :code, :message

      # Creates an instance of TextMagic::API::Error. Error code and error message
      # can be supplied as arguments or in a hash.
      #
      #  TextMagic::API::Error.new(code, message)
      #  TextMagic::API::Error.new('error_code' => code, 'error_message' => message)
      def initialize(*args)
        if args.first.is_a?(Hash)
          @code, @message = args.first['error_code'], args.first['error_message']
        else
          @code, @message = args
        end
      end

      def to_s
        "#{@message} (#{@code})"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
bobes-textmagic-0.3.0 lib/error.rb
bobes-textmagic-0.3.1 lib/error.rb
bobes-textmagic-0.3.2 lib/error.rb
bobes-textmagic-0.3.3 lib/error.rb
textmagic-0.3.2 lib/error.rb
textmagic-0.3.0 lib/error.rb
textmagic-0.3.3 lib/error.rb
textmagic-0.3.1 lib/error.rb