mirror of
https://github.com/internetee/registry.git
synced 2025-05-22 04:09:52 +02:00
Make EPP errors more compact
This commit is contained in:
parent
0a2ed60b9e
commit
7b750b7d9b
4 changed files with 20 additions and 46 deletions
|
@ -4,6 +4,7 @@ module EppErrors
|
|||
def construct_epp_errors
|
||||
epp_errors = []
|
||||
errors.messages.each do |key, values|
|
||||
next if key == :epp_errors
|
||||
if self.class.reflect_on_association(key)
|
||||
epp_errors << collect_child_errors(key)
|
||||
end
|
||||
|
@ -71,4 +72,11 @@ module EppErrors
|
|||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def add_epp_error(code, obj, val, msg)
|
||||
errors[:epp_errors] ||= []
|
||||
t = errors.generate_message(*msg) if msg.is_a?(Array)
|
||||
t = msg if msg.is_a?(String)
|
||||
errors[:epp_errors] << { code: code, msg: t, value: { val: val, obj: obj } }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -85,11 +85,9 @@ class Domain < ActiveRecord::Base
|
|||
def attach_owner_contact(code)
|
||||
self.owner_contact = Contact.find_by(code: code)
|
||||
|
||||
errors.add(:owner_contact, {
|
||||
obj: 'registrant',
|
||||
val: code,
|
||||
msg: I18n.t('errors.messages.epp_registrant_not_found')
|
||||
}) unless owner_contact
|
||||
return if owner_contact
|
||||
|
||||
add_epp_error('2303', 'registrant', code, [:owner_contact, :not_found])
|
||||
end
|
||||
|
||||
def attach_contacts(contacts)
|
||||
|
@ -100,11 +98,7 @@ class Domain < ActiveRecord::Base
|
|||
attach_contact(k, contact)
|
||||
else
|
||||
# Detailed error message with value to display in EPP response
|
||||
errors.add(:domain_contacts, {
|
||||
obj: 'contact',
|
||||
val: x[:contact],
|
||||
msg: errors.generate_message(:domain_contacts, :not_found)
|
||||
})
|
||||
add_epp_error('2303', 'contact', x[:contact], [:domain_contacts, :not_found])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -127,13 +121,7 @@ class Domain < ActiveRecord::Base
|
|||
nameservers.build(ns_attrs)
|
||||
|
||||
next if existing.empty?
|
||||
|
||||
errors.add(:nameservers, {
|
||||
code: '2302',
|
||||
obj: 'hostObj',
|
||||
val: ns_attrs[:hostname],
|
||||
msg: errors.generate_message(:nameservers, :taken)
|
||||
})
|
||||
add_epp_error('2302', 'hostObj', ns_attrs[:hostname], [:nameservers, :taken])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -153,11 +141,7 @@ class Domain < ActiveRecord::Base
|
|||
v.each do |x|
|
||||
contact = domain_contacts.joins(:contact).where(contacts: { code: x[:contact] })
|
||||
if contact.blank?
|
||||
errors.add(:domain_contacts, {
|
||||
obj: 'contact',
|
||||
val: x[:contact],
|
||||
msg: errors.generate_message(:domain_contacts, :not_found)
|
||||
})
|
||||
add_epp_error('2303', 'contact', x[:contact], [:domain_contacts, :not_found])
|
||||
else
|
||||
to_delete << contact
|
||||
end
|
||||
|
@ -172,11 +156,7 @@ class Domain < ActiveRecord::Base
|
|||
ns_list.each do |ns_attrs|
|
||||
nameserver = nameservers.where(ns_attrs)
|
||||
if nameserver.blank?
|
||||
errors.add(:nameservers, {
|
||||
obj: 'hostObj',
|
||||
val: ns_attrs[:hostname],
|
||||
msg: errors.generate_message(:nameservers, :not_found)
|
||||
})
|
||||
add_epp_error('2303', 'hostObj', ns_attrs[:hostname], [:nameservers, :not_found])
|
||||
else
|
||||
to_delete << nameserver
|
||||
end
|
||||
|
@ -190,11 +170,7 @@ class Domain < ActiveRecord::Base
|
|||
status_list.each do |x|
|
||||
status = domain_statuses.joins(:setting).where(settings: { value: x[:value] })
|
||||
if status.blank?
|
||||
errors.add(:domain_statuses, {
|
||||
obj: 'status',
|
||||
val: x[:value],
|
||||
msg: errors.generate_message(:domain_statuses, :not_found)
|
||||
})
|
||||
add_epp_error('2303', 'status', x[:value], [:domain_statuses, :not_found])
|
||||
else
|
||||
to_delete << status
|
||||
end
|
||||
|
@ -246,11 +222,8 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def validate_exp_dates(cur_exp_date)
|
||||
errors.add(:valid_to, {
|
||||
obj: 'curExpDate',
|
||||
val: cur_exp_date,
|
||||
msg: I18n.t('errors.messages.epp_exp_dates_do_not_match')
|
||||
}) if cur_exp_date.to_date != valid_to
|
||||
return if cur_exp_date.to_date == valid_to
|
||||
add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match'))
|
||||
end
|
||||
|
||||
def epp_code_map
|
||||
|
@ -263,8 +236,7 @@ class Domain < ActiveRecord::Base
|
|||
],
|
||||
'2306' => [ # Parameter policy error
|
||||
[:owner_contact, :blank],
|
||||
[:admin_contacts, :blank],
|
||||
[:valid_to, :epp_exp_dates_do_not_match]
|
||||
[:admin_contacts, :blank]
|
||||
],
|
||||
'2004' => [ # Parameter value range error
|
||||
[:nameservers, :out_of_range,
|
||||
|
@ -275,12 +247,6 @@ class Domain < ActiveRecord::Base
|
|||
],
|
||||
[:period, :out_of_range]
|
||||
],
|
||||
'2303' => [ # Object does not exist
|
||||
[:owner_contact, :epp_registrant_not_found],
|
||||
[:domain_contacts, :not_found],
|
||||
[:nameservers, :not_found],
|
||||
[:domain_statuses, :not_found]
|
||||
],
|
||||
'2200' => [
|
||||
[:auth_info, :wrong_pw]
|
||||
]
|
||||
|
|
|
@ -46,6 +46,7 @@ en:
|
|||
taken: 'Domain name already exists'
|
||||
owner_contact:
|
||||
blank: 'Registrant is missing'
|
||||
not_found: 'Registrant not found'
|
||||
domain_contacts:
|
||||
not_found: 'Contact was not found'
|
||||
admin_contacts:
|
||||
|
|
|
@ -296,7 +296,6 @@ describe 'EPP Domain', epp: true do
|
|||
expect(rem_cnt).to be_falsey
|
||||
|
||||
response = epp_request('domains/update_remove_objects.xml')
|
||||
|
||||
expect(response[:results][0][:result_code]).to eq('2303')
|
||||
expect(response[:results][0][:msg]).to eq('Contact was not found')
|
||||
expect(response[:results][0][:value]).to eq('mak21')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue