diff --git a/app/controllers/concerns/idv/document_capture_concern.rb b/app/controllers/concerns/idv/document_capture_concern.rb index 664d0c0beb5..3fd24874cd1 100644 --- a/app/controllers/concerns/idv/document_capture_concern.rb +++ b/app/controllers/concerns/idv/document_capture_concern.rb @@ -12,13 +12,8 @@ def handle_stored_result(user: current_user, store_in_session: true) flash[:success] = t('doc_auth.headings.capture_complete') successful_response else - FormResponse.new( - { - success: false, - errors: error_hash(message), - extra: { stored_result_present: stored_result.present? }, - }, - ) + extra = { stored_result_present: stored_result.present? } + failure(nil, extra) end end @@ -26,10 +21,18 @@ def successful_response FormResponse.new(success: true) end + # copied from Flow::Failure module + def failure(message = nil, extra = nil) + form_response_params = { success: false } + form_response_params[:errors] = error_hash(message) + form_response_params[:extra] = extra unless extra.nil? + FormResponse.new(**form_response_params) + end + def error_hash(message) { message: message || I18n.t('doc_auth.errors.general.network_error'), - socure: stored_result&.errors[:socure], + socure: stored_result&.errors&.dig(:socure), } end