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