proper error message

This commit is contained in:
Anton Chuchkalov 2015-11-27 13:49:41 +03:00
parent fb6eb62063
commit c0846a50da

View File

@ -1,6 +1,10 @@
require_relative "devops_error"
class InvalidRecord < ::Devops::Exception::DevopsError
# message could be a String or a hash like
# {
# error_data: [{:key=>:provider, :message=>"Value can not be undefined"}]
# }
def initialize msg
if msg.is_a?(String)
super(msg)
@ -9,6 +13,17 @@ class InvalidRecord < ::Devops::Exception::DevopsError
end
end
def message
if @object
messages = @object[:error_data].map do |error_item|
"#{error_item[:key]}: #{error_item[:message]}"
end
"Following errors occured: \n#{messages.join('\n')}"
else
super
end
end
def http_status
400
end