class Noise::Notification
Provides detailed information about exception and request context.
Constants
- ERROR
- INFO
- SEVERITIES
- WARNING
Public Class Methods
extract(key, extractor)
click to toggle source
Extract info from request and it to Bugsnag notification @param key [Symbol, String] name of the parameter @param extractor [#call] @return [void]
class ApiClientExtractor def call(env) env.slice(:client_version, :client_id) end end Notification.extract(:api_client, ApiClientExtractor)
# File lib/noise/notification.rb, line 47 def extract(key, extractor) extractors[key] = extractor end
new(error, env)
click to toggle source
@param error [StandardError] @param env [Hash] rack env
@see http://www.rubydoc.info/github/rack/rack/master/file/SPEC
# File lib/noise/notification.rb, line 56 def initialize(error, env) @error = error @env = env end
register(error_class, severity:)
click to toggle source
@param error_class [Class<StandardError>, String] @param severity [Symbol] severity constant
# File lib/noise/notification.rb, line 27 def register(error_class, severity:) if SEVERITIES.include?(severity) severities[error_class.to_s] = severity else fail ArgumentError, "Wrong severity `#{severity}`, allowed: #{SEVERITIES}" end end
Public Instance Methods
severity()
click to toggle source
@return [String] Error severity
# File lib/noise/notification.rb, line 69 def severity severities[@error.class.name].to_s end
to_hash()
click to toggle source
@return [{String, Any}]
# File lib/noise/notification.rb, line 62 def to_hash extractors.except('user').transform_values do |extractor| extractor.new.call(@env) end end
user_info()
click to toggle source
@return [Hash] User info
# File lib/noise/notification.rb, line 74 def user_info user = if extractors.key?('user') extractors['user'].new.call(@env) else {} end fail '`name` key is reserved to identify error itself' if user.key?('name') user.merge('name' => request.uuid) end
Private Instance Methods
request()
click to toggle source
# File lib/noise/notification.rb, line 87 def request @request ||= ActionDispatch::Request.new(@env) end