Improve EPP error handling

Fixes #539
This commit is contained in:
Artur Beljajev 2019-09-11 18:42:13 +03:00
parent 0a1405ae52
commit 77678681a6
18 changed files with 263 additions and 272 deletions

View file

@ -154,10 +154,17 @@ class Epp::Contact < Contact
type: ident_frame.attr('type'),
country_code: ident_frame.attr('cc'))
report_valid_ident_error if submitted_ident != identifier
if submitted_ident != identifier
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident'))
return
end
else
ident_update_attempt = ident_frame.text.present? && (ident_frame.text != ident)
report_ident_update_error if ident_update_attempt
if ident_update_attempt
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.ident_update'))
return
end
identifier = Ident.new(code: ident,
type: ident_frame.attr('type'),
@ -243,14 +250,4 @@ class Epp::Contact < Contact
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
self.legal_document_id = doc.id
end
private
def report_valid_ident_error
throw :epp_error, { code: '2308', msg: I18n.t('epp.contacts.errors.valid_ident') }
end
def report_ident_update_error
throw :epp_error, { code: '2308', msg: I18n.t('epp.contacts.errors.ident_update') }
end
end

View file

@ -451,10 +451,8 @@ class Epp::Domain < Domain
return super if frame.blank?
if discarded?
throw :epp_error, {
code: '2304',
msg: 'Object status prohibits operation',
}
add_epp_error('2304', nil, nil, 'Object status prohibits operation')
return
end
at = {}.with_indifferent_access
@ -531,10 +529,8 @@ class Epp::Domain < Domain
def epp_destroy(frame, user_id)
if discarded?
throw :epp_error, {
code: '2304',
msg: 'Object status prohibits operation',
}
add_epp_error('2304', nil, nil, 'Object status prohibits operation')
return
end
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
@ -554,10 +550,10 @@ class Epp::Domain < Domain
end
def set_pending_delete!
throw :epp_error, {
code: '2304',
msg: I18n.t(:object_status_prohibits_operation)
} unless pending_deletable?
unless pending_deletable?
add_epp_error('2304', nil, nil, I18n.t(:object_status_prohibits_operation))
return
end
self.delete_date = Time.zone.today + Setting.redemption_grace_period.days + 1.day
set_pending_delete
@ -601,10 +597,8 @@ class Epp::Domain < Domain
def transfer(frame, action, current_user)
if discarded?
throw :epp_error, {
code: '2106',
msg: 'Object is not eligible for transfer',
}
add_epp_error('2106', nil, nil, 'Object is not eligible for transfer')
return
end
@is_transfer = true
@ -624,10 +618,8 @@ class Epp::Domain < Domain
def query_transfer(frame, current_user)
if current_user.registrar == registrar
throw :epp_error, {
code: '2002',
msg: I18n.t(:domain_already_belongs_to_the_querying_registrar)
}
add_epp_error('2002', nil, nil, I18n.t(:domain_already_belongs_to_the_querying_registrar))
return
end
transaction do
@ -661,11 +653,10 @@ class Epp::Domain < Domain
def approve_transfer(frame, current_user)
pt = pending_transfer
if current_user.registrar != pt.old_registrar
throw :epp_error, {
msg: I18n.t('transfer_can_be_approved_only_by_current_registrar'),
code: '2304'
}
add_epp_error('2304', nil, nil, I18n.t('transfer_can_be_approved_only_by_current_registrar'))
return
end
transaction do
@ -687,11 +678,10 @@ class Epp::Domain < Domain
def reject_transfer(frame, current_user)
pt = pending_transfer
if current_user.registrar != pt.old_registrar
throw :epp_error, {
msg: I18n.t('transfer_can_be_rejected_only_by_current_registrar'),
code: '2304'
}
add_epp_error('2304', nil, nil, I18n.t('transfer_can_be_rejected_only_by_current_registrar'))
return
end
transaction do

View file

@ -26,6 +26,7 @@ module Epp
object_association_prohibits_operation: 2305,
parameter_value_policy_error: 2306,
data_management_policy_violation: 2308,
command_failed: 2400,
authentication_error_server_closing_connection: 2501,
}.freeze
private_constant :KEY_TO_VALUE
@ -52,6 +53,7 @@ module Epp
2305 => 'Object association prohibits operation',
2306 => 'Parameter value policy error',
2308 => 'Data management policy violation',
2400 => 'Command failed',
2501 => 'Authentication error; server closing connection',
}.freeze
private_constant :DEFAULT_DESCRIPTIONS