class ErrorResponse def initialize(error_code) error_object = I18n.t(:error_codes)[error_code] @error_code = error_code.to_s @http_status = error_object[:http_status] @message = error_object[:message] @details = error_object[:details] end # attributes that can be read attr_reader :error_code, :http_status, :message, :details # custom json format def as_json(options = nil) { :status => "#{http_status}", :error => { :error_code => error_code, :message => message, :details => details } } end # custom xml format def to_xml output = "\n" output += "\n" output += " #{http_status}\n" output += " \n" output += " #{error_code}\n" output += " #{message}\n" output += "
#{details}
\n" output += "
\n" output += "
" return output end end