Class: Rscratch::Exception

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/rscratch/exception.rb

Constant Summary collapse

STATUS =
%w(new under_development resolved)

Class Method Summary collapse

Class Method Details

.find_or_add_exception(exc, _controller, _action, _env) ⇒ Object

Log unique exceptions



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/rscratch/exception.rb', line 53

def self.find_or_add_exception exc,_controller,_action,_env              
  _excp = Exception.by_exception(exc.class).by_message(exc.message).by_controller(_controller).by_action(_action).by_environment(_env)
  if _excp.present?
    return _excp.first
  else
    _new_excp = Exception.create( :exception        => exc.class,
                                  :message          => exc.message,
                                  :controller       => _controller,
                                  :action           => _action,
                                  :app_environment  => _env,
                                  :status           => "new")
    return _new_excp
  end
end

.log(exc, request) ⇒ Object

Log an exception



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/rscratch/exception.rb', line 37

def self.log(exc,request) 
  _exception = self.find_or_add_exception(exc,request.filtered_parameters["controller"].camelize,request.filtered_parameters["action"],Rails.env.camelize)
  _excp_log = ExceptionLog.new(
                              :description         => exc.inspect,
                              :backtrace           => exc.backtrace.join("\n"),
                              :request_url         => request.original_url,
                              :request_method      => request.request_method,
                              :parameters          => request.filtered_parameters,
                              :user_agent          => request.user_agent,
                              :client_ip           => request.remote_ip,
                              :status              => "new")
  _exception.exception_logs << _excp_log
  return _exception
end