Refactor error handling to common

This commit is contained in:
Martin Lensment 2014-08-01 12:06:32 +03:00
parent fb8cba9ef4
commit 3fc3bfc1c4
2 changed files with 12 additions and 8 deletions

View file

@ -32,6 +32,14 @@ module Epp::Common
@current_epp_user ||= EppUser.find(epp_session[:epp_user_id]) if epp_session[:epp_user_id]
end
def handle_errors(error_code_map, obj)
obj.errors.each do |key, err|
error_code_map.each do |code, values|
epp_errors << {code: code, msg: err} and break if values.any? {|x| obj.errors.added?(key, x) }
end
end
end
def validate_request
type = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]
return unless type

View file

@ -20,6 +20,7 @@ module Epp::DomainsHelper
end
### HELPER METHODS ###
private
def domain_create_params
ph = params_hash['epp']['command']['create']['create']
@ -50,17 +51,12 @@ module Epp::DomainsHelper
end
def handle_errors
error_code_map = {
super({
'2302' => [:epp_domain_taken, :epp_domain_reserved],
'2306' => [:blank],
'2303' => [:epp_contact_not_found]
}
@domain.errors.each do |key, err|
error_code_map.each do |code, values|
epp_errors << {code: code, msg: err} and break if values.any? {|x| @domain.errors.added?(key, x) }
end
end
}, @domain
)
end
end