Sha256: 3e204801e7cc740cd36e58a8b087d9d7cb40b8662e4dce5d426e8030bbd27fab

Contents?: true

Size: 732 Bytes

Versions: 3

Compression:

Stored size: 732 Bytes

Contents

require 'htmlentities'
#
# We are opening up Exception and adding to_xml and to_json.
#
class Exception

  def exception_type
    self.class.to_s ? self.class.to_s.split("::").last : 'None'
  end

  def to_xml
    "<errors><error>#{HTMLEntities.new.encode(self.message)}</error><type>#{self.exception_type}</type></errors>"
  end

  def to_json
    "{\"error\":#{ActiveSupport::JSON.encode(self.message.gsub(/\r/, ' ').gsub(/\n/, ' ').squeeze(' '))}, \"type\":\"#{self.exception_type}\"}"
  end

end

module Egregious
  class Error < StandardError
    attr_reader :http_status
    attr_reader :message
    def initialize(message=nil, http_status=nil)
         @message = message
         @http_status = http_status
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
egregious-0.2.13 lib/egregious/extensions/exception.rb
egregious-0.2.12 lib/egregious/extensions/exception.rb
egregious-0.2.10 lib/egregious/extensions/exception.rb