-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
notifier.rb
68 lines (53 loc) · 1.59 KB
/
notifier.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
module Isolator
# Wrapper over different notifications methods (exceptions, logging, uniform notifier)
class Notifier
attr_reader :exception, :backtrace
def initialize(exception, backtrace = caller)
@exception = exception
@backtrace = backtrace
end
def call
log_exception
send_notifications if send_notifications?
raise(exception.class, exception.message, filtered_backtrace) if raise_exceptions?
end
private
def raise_exceptions?
Isolator.config.raise_exceptions?
end
def send_notifications?
Isolator.config.send_notifications?
end
def log_exception
return unless Isolator.config.logger
msg = "[ISOLATOR EXCEPTION]\n" \
"#{exception.message}"
filtered_backtrace.each do |offense_line|
msg += "\n ↳ #{offense_line}"
end
Isolator.config.logger.warn(msg)
end
def send_notifications
return unless uniform_notifier_loaded?
::UniformNotifier.active_notifiers.each do |notifier|
notifier.out_of_channel_notify exception.message
end
end
def filtered_backtrace
Isolator.config.backtrace_filter.call(backtrace)
end
def uniform_notifier_loaded?
return true if defined?(::UniformNotifier)
begin
require "uniform_notifier"
rescue LoadError
warn(
"Please, install and configure 'uniform_notifier' to send notifications:\n" \
"# Gemfile\n" \
"gem 'uniform_notifer', '~> 1.11', require: false"
)
end
end
end
end