Class: RubyCms::VisitorError
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- RubyCms::VisitorError
- Defined in:
- app/models/ruby_cms/visitor_error.rb
Class Method Summary collapse
- .log_error(exception, request) ⇒ Object
-
.log_routing_error(request) ⇒ Object
Log routing errors (404s) from catch-all route.
Instance Method Summary collapse
- #browser_info ⇒ Object
-
#codepath ⇒ Object
Returns the code path: backtrace for exceptions, or synthetic path for routing errors.
Class Method Details
.log_error(exception, request) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'app/models/ruby_cms/visitor_error.rb', line 14 def self.log_error(exception, request) create!( **base_request_attrs(request), **exception_attrs(exception), request_params: sanitize_params(request.params) ) rescue StandardError => e Rails.logger.error "Failed to log visitor error: #{e.message}" end |
.log_routing_error(request) ⇒ Object
Log routing errors (404s) from catch-all route. Called by RubyCms::ErrorsController#not_found
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/ruby_cms/visitor_error.rb', line 26 def self.log_routing_error(request) return if Rails.env.development? return if request.path.start_with?("/admin") create!( **base_request_attrs(request), error_class: "ActionController::RoutingError", error_message: (request), backtrace: nil, request_params: nil ) rescue StandardError => e Rails.logger.error "Failed to log routing error: #{e.message}" end |
Instance Method Details
#browser_info ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/ruby_cms/visitor_error.rb', line 55 def browser_info return "Unknown" if user_agent.blank? case user_agent when /Chrome/ then "Chrome" when /Firefox/ then "Firefox" when /Safari(?!.*Chrome)/ then "Safari" when /Edge/ then "Edge" else "Other" end end |
#codepath ⇒ Object
Returns the code path: backtrace for exceptions, or synthetic path for routing errors
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/ruby_cms/visitor_error.rb', line 42 def codepath if backtrace.present? backtrace elsif error_class == "ActionController::RoutingError" " Request \u2192 Router (no matching route) \u2192 RubyCms::ErrorsController#not_found\n (Routing errors don't generate stack traces; the request never reached a controller action.)\n TEXT\n else\n \"No stack trace available.\"\n end\nend\n".strip |