class Bugsnag::Middleware::SuggestionData

Attaches any “Did you mean?” suggestions to the report

Constants

CAPTURE_REGEX
DELIMITER

Public Class Methods

new(bugsnag) click to toggle source
# File lib/bugsnag/middleware/suggestion_data.rb, line 9
def initialize(bugsnag)
  @bugsnag = bugsnag
end

Public Instance Methods

call(event) click to toggle source
# File lib/bugsnag/middleware/suggestion_data.rb, line 13
def call(event)
  matches = []

  event.errors.each do |error|
    match = CAPTURE_REGEX.match(error.error_message)

    next unless match

    suggestions = match.captures[0].split(DELIMITER)
    matches.concat(suggestions.map(&:strip))
  end

  if matches.size == 1
    event.add_metadata(:error, { suggestion: matches.first })
  elsif matches.size > 1
    event.add_metadata(:error, { suggestions: matches })
  end

  @bugsnag.call(event)
end