Class: Sq::Dbsync::ErrorHandler
- Inherits:
-
Object
- Object
- Sq::Dbsync::ErrorHandler
- Defined in:
- lib/sq/dbsync/error_handler.rb
Overview
Handles redacting sensitive information for error messages, and delegating response to a user-defined handler.
Instance Method Summary collapse
-
#initialize(config) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
- #notify_error(tag, ex) ⇒ Object
- #redact_passwords ⇒ Object
- #with_massaged_exception(*massagers) ⇒ Object
- #wrap(&block) ⇒ Object
Constructor Details
#initialize(config) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
7 8 9 10 |
# File 'lib/sq/dbsync/error_handler.rb', line 7 def initialize(config) @config = config @handler = config.fetch(:error_handler, ->(ex) {}) end |
Instance Method Details
#notify_error(tag, ex) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/sq/dbsync/error_handler.rb', line 22 def notify_error(tag, ex) with_massaged_exception(redact_passwords) do raise ex, "[%s] %s" % [tag, ex.], ex.backtrace end rescue => e handler[e] end |
#redact_passwords ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sq/dbsync/error_handler.rb', line 30 def redact_passwords lambda do || ( config[:sources].values + [config[:target]] ).compact.inject() do |m, | if [:password] m.gsub([:password], 'REDACTED') else m end end end end |
#with_massaged_exception(*massagers) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/sq/dbsync/error_handler.rb', line 44 def with_massaged_exception(*massagers) yield rescue => ex = massagers.inject(ex.) do |a, v| v.call(a) end raise ex, , ex.backtrace end |
#wrap(&block) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/sq/dbsync/error_handler.rb', line 12 def wrap(&block) begin with_massaged_exception(redact_passwords, &block) rescue => ex handler[ex] raise ex end end |