Skip to content

Commit

Permalink
Merge pull request #171 from petrblaho/corrects-notification-params-h…
Browse files Browse the repository at this point in the history
…andling

Corrects handling of Notification params
(cherry picked from commit a29bbed)

https://bugzilla.redhat.com/show_bug.cgi?id=1519469
  • Loading branch information
aufi authored and simaishi committed Nov 30, 2017
1 parent 674895c commit dc0a0ce
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/models/manageiq/providers/openstack/helper_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ def with_notification(type, options: {})
error_options = options.delete(:error) || {}
success_options.merge!(options)
error_options.merge!(options)

# copy subject, initiator and cause from options
named_options_keys = [:subject, :initiator, :cause]
named_options = {}
named_options_keys.map do |key|
named_options[key] = options.fetch(key, nil)
end

begin
yield
rescue => ex
# Fog specific
error_message = parse_error_message_from_fog_response(ex.to_s)
Notification.create(:type => "#{type}_error".to_sym, :options => error_options.merge(:error_message => error_message))
Notification.create(:type => "#{type}_error".to_sym, :options => error_options.merge(:error_message => error_message), **named_options)
raise
else
Notification.create(:type => "#{type}_success".to_sym, :options => success_options)
Notification.create(:type => "#{type}_success".to_sym, :options => success_options, **named_options)
end
end
end
Expand Down

0 comments on commit dc0a0ce

Please sign in to comment.