mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +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)
|
||||
obj.errors.each do |key, err|
|
||||
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)
|
||||
epp_errors << {
|
||||
code: code,
|
||||
|
@ -45,7 +50,7 @@ module Epp::Common
|
|||
epp_errors << {
|
||||
code: code,
|
||||
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
|
||||
|
|
|
@ -59,7 +59,7 @@ module Epp::DomainsHelper
|
|||
def handle_errors
|
||||
super({
|
||||
'2302' => [:epp_domain_taken, :epp_domain_reserved],
|
||||
'2306' => [:blank],
|
||||
'2306' => [:blank, [:out_of_range, {min: 1, max: 13}]],
|
||||
'2303' => [:epp_contact_not_found]
|
||||
}, @domain
|
||||
)
|
||||
|
|
|
@ -75,9 +75,11 @@ class Domain < ActiveRecord::Base
|
|||
def validate_nameservers_count
|
||||
errors.add(:nameservers, :blank) if nameservers.empty?
|
||||
|
||||
if nameservers.count <= 1 || nameservers.count > 13
|
||||
errors.add(:nameservers, I18n.t('errors.messages.epp_nameservers_range_fail', min: 1, max: 13))
|
||||
unless nameservers.count.between?(1, 13)
|
||||
errors.add(:nameservers, :out_of_range, {min: 1, max: 13})
|
||||
end
|
||||
|
||||
errors.empty?
|
||||
end
|
||||
|
||||
def validate_admin_contacts_count
|
||||
|
|
|
@ -45,6 +45,7 @@ en:
|
|||
blank: 'Required parameter missing - admin contact'
|
||||
nameservers:
|
||||
blank: 'Required parameter missing - nameserver'
|
||||
out_of_range: 'Domain must have %{min}-%{max} nameservers'
|
||||
|
||||
errors:
|
||||
messages:
|
||||
|
|
|
@ -73,7 +73,7 @@ describe 'EPP Domain', epp: true do
|
|||
expect(response[:msg]).to eq('Required parameter missing - nameserver')
|
||||
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')
|
||||
expect(response[:result_code]).to eq('2306')
|
||||
expect(response[:msg]).to eq('Domain must have 1-13 nameservers')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue