Exception: Exception
- Defined in:
- lib/egregious/extensions/exception.rb
Overview
We are opening up Exception and adding to_xml and to_json.
Instance Method Summary collapse
Instance Method Details
#exception_type ⇒ Object
7 8 9 |
# File 'lib/egregious/extensions/exception.rb', line 7 def exception_type self.class.to_s ? self.class.to_s.split("::").last : 'None' end |
#to_json ⇒ Object
15 16 17 |
# File 'lib/egregious/extensions/exception.rb', line 15 def to_json "{\"error\":#{ActiveSupport::JSON.encode(self.message.gsub(/\r/, ' ').gsub(/\n/, ' ').squeeze(' '))}, \"type\":\"#{self.exception_type}\"}" end |
#to_xml ⇒ Object
11 12 13 |
# File 'lib/egregious/extensions/exception.rb', line 11 def to_xml "<errors><error>#{HTMLEntities.new.encode(self.message)}</error><type>#{self.exception_type}</type></errors>" end |