Class: SolidErrors::Subscriber
- Inherits:
-
Object
- Object
- SolidErrors::Subscriber
- Defined in:
- lib/solid_errors/subscriber.rb
Constant Summary collapse
- IGNORED_ERRORS =
["ActionController::RoutingError", "AbstractController::ActionNotFound", "ActionController::MethodNotAllowed", "ActionController::UnknownHttpMethod", "ActionController::NotImplemented", "ActionController::UnknownFormat", "ActionController::InvalidAuthenticityToken", "ActionController::InvalidCrossOriginRequest", "ActionDispatch::Http::Parameters::ParseError", "ActionController::BadRequest", "ActionController::ParameterMissing", "ActiveRecord::RecordNotFound", "ActionController::UnknownAction", "ActionDispatch::Http::MimeNegotiation::InvalidType", "Rack::QueryParser::ParameterTypeError", "Rack::QueryParser::InvalidParameterError", "CGI::Session::CookieStore::TamperedWithCookie", "Mongoid::Errors::DocumentNotFound", "Sinatra::NotFound", "Sidekiq::JobRetry::Skip"].map(&:freeze).freeze
Instance Method Summary collapse
- #ignore_by_class?(error_class_name) ⇒ Boolean
- #report(error, handled:, severity:, context:, source: nil) ⇒ Object
- #s(data) ⇒ Object
Instance Method Details
#ignore_by_class?(error_class_name) ⇒ Boolean
51 52 53 54 55 56 57 |
# File 'lib/solid_errors/subscriber.rb', line 51 def ignore_by_class?(error_class_name) IGNORED_ERRORS.any? do |ignored_class| ignored_class_name = ignored_class.respond_to?(:name) ? ignored_class.name : ignored_class ignored_class_name == error_class_name end end |
#report(error, handled:, severity:, context:, source: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/solid_errors/subscriber.rb', line 24 def report(error, handled:, severity:, context:, source: nil) return if ignore_by_class?(error.class.name) error_attributes = { exception_class: error.class.name, message: s(error.), severity: severity, source: source } fingerprint = Digest::SHA256.hexdigest(error_attributes.values.join) if (record = SolidErrors::Error.find_by(fingerprint: fingerprint)) record.update!(resolved_at: nil, updated_at: Time.now) else record = SolidErrors::Error.create!(error_attributes.merge(fingerprint: fingerprint)) end SolidErrors::Occurrence.create( error_id: record.id, backtrace: error.backtrace&.join("\n"), context: s(context) ) end |