Class: Bugsnag::Middleware::SuggestionData

Inherits:
Object
  • Object
show all
Defined in:
lib/bugsnag/middleware/suggestion_data.rb

Overview

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

Constant Summary collapse

CAPTURE_REGEX =
/Did you mean\?([\s\S]+)$/
DELIMITER =
"\n"

Instance Method Summary collapse

Constructor Details

#initialize(bugsnag) ⇒ SuggestionData

Returns a new instance of SuggestionData.



9
10
11
# File 'lib/bugsnag/middleware/suggestion_data.rb', line 9

def initialize(bugsnag)
  @bugsnag = bugsnag
end

Instance Method Details

#call(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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.(:error, { suggestion: matches.first })
  elsif matches.size > 1
    event.(:error, { suggestions: matches })
  end

  @bugsnag.call(event)
end