mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Collect errors from parent
This commit is contained in:
parent
684a4ab4f1
commit
a8e0cba9d3
2 changed files with 58 additions and 0 deletions
|
@ -6,6 +6,8 @@ module Epp::DomainsHelper
|
|||
if @domain.save && @domain.attach_contacts(domain_contacts) && @domain.attach_nameservers(domain_nameservers)
|
||||
render '/epp/domains/create'
|
||||
else
|
||||
@domain.construct_epp_errors
|
||||
|
||||
handle_errors
|
||||
render '/epp/error'
|
||||
raise ActiveRecord::Rollback
|
||||
|
|
|
@ -22,6 +22,62 @@ class Domain < ActiveRecord::Base
|
|||
validates :name, :owner_contact, presence: true
|
||||
validates_associated :nameservers
|
||||
|
||||
# after_validation :construct_epp_errors
|
||||
|
||||
attr_accessor :epp_errors
|
||||
|
||||
EPP_CODE_MAP = {
|
||||
'2302' => ['Domain name already exists', 'Domain name is reserved or restricted'],
|
||||
'2306' => ['Registrant is missing', 'Nameservers count must be between 1-13', 'Admin contact is missing'],
|
||||
'2303' => ['Contact was not found'],
|
||||
'2005' => ['Hostname is invalid', 'IP is invalid']
|
||||
}
|
||||
|
||||
EPP_OBJ_MAP = {
|
||||
nameservers: 'ns',
|
||||
name_dirty: 'domain'
|
||||
}
|
||||
|
||||
def construct_epp_errors
|
||||
epp_errors = []
|
||||
errors.messages.each do |key, values|
|
||||
if self.class.reflect_on_association(key)
|
||||
epp_errors = collect_child_errors
|
||||
else
|
||||
epp_errors = collect_parent_errors(key, values)
|
||||
end
|
||||
end
|
||||
|
||||
errors[:epp_errors] = epp_errors
|
||||
errors[:epp_errors].flatten!
|
||||
# binding.pry
|
||||
end
|
||||
|
||||
def collect_parent_errors(key, values)
|
||||
epp_errors = []
|
||||
values = [values] if values.is_a?(String)
|
||||
|
||||
values.each do |err|
|
||||
if err.is_a?(Hash)
|
||||
epp_errors << {code: find_epp_code(err[:msg]), msg: err[:msg], value: {val: err[:val], obj: err[:obj]}}
|
||||
else
|
||||
epp_errors << {code: find_epp_code(err), msg: err, value: {val: send(key), obj: EPP_OBJ_MAP[key]}}
|
||||
end
|
||||
end
|
||||
epp_errors
|
||||
end
|
||||
|
||||
def collect_child_errors
|
||||
|
||||
end
|
||||
|
||||
def find_epp_code(msg)
|
||||
EPP_CODE_MAP.each do |code, values|
|
||||
return code if values.include?(msg)
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
write_attribute(:name, SimpleIDN.to_unicode(value))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue