Project

General

Profile

« Previous | Next » 

Revision ab19a3e4

Added by Rahul Bajaj over 5 years ago

Fixes #24193 - introduced Foreman multiexception class

View differences:

lib/foreman/exception.rb
def to_s
message
end
def as_json
{ message: message }.to_json
end
end
class WrappedException < ::Foreman::Exception
......
end
end
class MultiException < ::Foreman::Exception
attr_reader :exceptions
def initialize(exceptions, message, *params)
super(message, *params)
raise "Can't create multi exception - not an array: #{exceptions}" unless exceptions.respond_to?(:to_a)
@exceptions = exceptions.to_a.dup.freeze
end
def to_s
return super if @exceptions.empty?
super + @exceptions.map(&:message)
end
def as_json
return super if @exceptions.empty?
(JSON[super].merge errors: @exceptions.map(&:message)).to_json
end
end
class FingerprintException < Foreman::Exception
def fingerprint
@params[0]

Also available in: Unified diff