Catch all errors on PIO import and show message

This commit is contained in:
Jure Grabnar 2018-11-23 20:47:48 +01:00
parent 2834edb286
commit 1c7a051551
2 changed files with 59 additions and 48 deletions

View file

@ -603,6 +603,7 @@ class ProtocolsController < ApplicationController
end
def protocolsio_import_create
begin
@protocolsio_too_big = false
@protocolsio_invalid_file = false
@protocolsio_no_file = false
@ -649,13 +650,21 @@ class ProtocolsController < ApplicationController
@json_object['steps']
)
end
@protocol = Protocol.new
respond_to do |format|
format.js {} # go to the js.erb file named the same as this controller,
# where a preview modal is rendered,
# and some modals get closed and opened
end
rescue => e
Rails.logger.error(e.message)
@protocolsio_general_error = true
respond_to do |format|
format.js {} # go to the js.erb file named the same as this controller,
# where a preview modal is rendered,
# and some modals get closed and opened
end
end
end
def protocolsio_import_save

View file

@ -5,6 +5,8 @@ $('#modal-import-json-protocol').on('hidden.bs.modal', function () {
$('#modal-import-json-protocol').modal('hide');
HelperModule.flashAlertMsg(I18n.t('my_modules.protocols.load_from_file_size_error',
{ size: $(document.body).data('file-max-size-mb') ) }, 'danger');
<% elsif @protocolsio_general_error %>
$('#pio_no_file_error_span').addClass('has-error').html('<span class="help-block"> <%= t('protocols.import_export.load_file_error') %></span>');
<% elsif @protocolsio_invalid_file %>
$('#modal-import-json-protocol').modal('hide');
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_invalid_error') %>','danger');