mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Renewed logic for error handling
This commit is contained in:
parent
86dc8321c6
commit
8dfb80c1ea
5 changed files with 13 additions and 5 deletions
|
@ -35,6 +35,11 @@ module Epp::Common
|
||||||
def handle_errors(error_code_map, obj)
|
def handle_errors(error_code_map, obj)
|
||||||
obj.errors.each do |key, err|
|
obj.errors.each do |key, err|
|
||||||
error_code_map.each do |code, values|
|
error_code_map.each do |code, values|
|
||||||
|
|
||||||
|
has_error = Proc.new do |x|
|
||||||
|
x.is_a?(Array) ? obj.errors.added?(key, x[0], x[1]) : obj.errors.added?(key, x)
|
||||||
|
end
|
||||||
|
|
||||||
if err.is_a?(Hash)
|
if err.is_a?(Hash)
|
||||||
epp_errors << {
|
epp_errors << {
|
||||||
code: code,
|
code: code,
|
||||||
|
@ -45,7 +50,7 @@ module Epp::Common
|
||||||
epp_errors << {
|
epp_errors << {
|
||||||
code: code,
|
code: code,
|
||||||
msg: err,
|
msg: err,
|
||||||
} and break if values.any? {|x| obj.errors.added?(key, x) }
|
} and break if values.any? {|x| has_error.call(x)}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ module Epp::DomainsHelper
|
||||||
def handle_errors
|
def handle_errors
|
||||||
super({
|
super({
|
||||||
'2302' => [:epp_domain_taken, :epp_domain_reserved],
|
'2302' => [:epp_domain_taken, :epp_domain_reserved],
|
||||||
'2306' => [:blank],
|
'2306' => [:blank, [:out_of_range, {min: 1, max: 13}]],
|
||||||
'2303' => [:epp_contact_not_found]
|
'2303' => [:epp_contact_not_found]
|
||||||
}, @domain
|
}, @domain
|
||||||
)
|
)
|
||||||
|
|
|
@ -75,9 +75,11 @@ class Domain < ActiveRecord::Base
|
||||||
def validate_nameservers_count
|
def validate_nameservers_count
|
||||||
errors.add(:nameservers, :blank) if nameservers.empty?
|
errors.add(:nameservers, :blank) if nameservers.empty?
|
||||||
|
|
||||||
if nameservers.count <= 1 || nameservers.count > 13
|
unless nameservers.count.between?(1, 13)
|
||||||
errors.add(:nameservers, I18n.t('errors.messages.epp_nameservers_range_fail', min: 1, max: 13))
|
errors.add(:nameservers, :out_of_range, {min: 1, max: 13})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
errors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_admin_contacts_count
|
def validate_admin_contacts_count
|
||||||
|
|
|
@ -45,6 +45,7 @@ en:
|
||||||
blank: 'Required parameter missing - admin contact'
|
blank: 'Required parameter missing - admin contact'
|
||||||
nameservers:
|
nameservers:
|
||||||
blank: 'Required parameter missing - nameserver'
|
blank: 'Required parameter missing - nameserver'
|
||||||
|
out_of_range: 'Domain must have %{min}-%{max} nameservers'
|
||||||
|
|
||||||
errors:
|
errors:
|
||||||
messages:
|
messages:
|
||||||
|
|
|
@ -73,7 +73,7 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:msg]).to eq('Required parameter missing - nameserver')
|
expect(response[:msg]).to eq('Required parameter missing - nameserver')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create domain with too many nameservers', pending: true do
|
it 'does not create domain with too many nameservers' do
|
||||||
response = epp_request('domains/create_w_too_many_nameservers.xml')
|
response = epp_request('domains/create_w_too_many_nameservers.xml')
|
||||||
expect(response[:result_code]).to eq('2306')
|
expect(response[:result_code]).to eq('2306')
|
||||||
expect(response[:msg]).to eq('Domain must have 1-13 nameservers')
|
expect(response[:msg]).to eq('Domain must have 1-13 nameservers')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue