Added error handling for protocol import [SCI-8735]

This commit is contained in:
Anton 2023-07-13 11:51:35 +02:00
parent d419608f18
commit 25b11bfb24
3 changed files with 25 additions and 1 deletions

View file

@ -16,6 +16,9 @@
<button v-if="state === 'confirm'" type="button"
class="btn btn-primary"
@click.stop.prevent="confirm">{{ i18n.t('protocols.import_modal.import') }}</button>
<button v-else-if="state === 'failed'" type="button"
class="btn btn-primary"
data-dismiss="modal">{{ i18n.t('protocols.import_modal.close') }}</button>
<button v-else type="button"
class="btn btn-primary"
:disabled="state === 'in_progress'"
@ -97,6 +100,7 @@
clearInterval(this.jobPollInterval);
break;
case 'failed':
this.state = 'failed';
clearInterval(this.jobPollInterval);
break;
}

View file

@ -29,7 +29,10 @@ module Protocols
}
)
raise RequestFailureException, "#{response.code}: #{response.message}" unless response.success?
unless response.success?
create_failed_notification!
raise RequestFailureException, "#{response.code}: #{response.message}"
end
ActiveRecord::Base.transaction do
@protocol = @team.protocols.new(
@ -46,6 +49,9 @@ module Protocols
@protocol.save!
create_steps!(response['steps']) if response['steps'].present?
create_notification!
rescue ActiveRecord::RecordInvalid => e
create_failed_notification!
Rails.logger.error(e.message)
end
end
@ -146,5 +152,14 @@ module Protocols
UserNotification.create!(notification: notification, user: @user)
end
def create_failed_notification!
notification = Notification.create!(
type_of: :deliver_error,
title: I18n.t('protocols.import_export.import_protocol_notification_error.title')
)
UserNotification.create!(notification: notification, user: @user)
end
end
end

View file

@ -2697,6 +2697,9 @@ en:
done:
title: "Importing completed"
body_html: 'The protocol has been successfully imported. You can access the draft of protocol template <a href="%{url}">here.</a>'
failed:
title: "Import failed"
body_html: "We're sorry, but the file import has failed. Please ensure you have a stable internet connection and try again. If the problem persists, please contact support for further assistance."
import: "Import"
cancel: "Cancel"
close: "Close"
@ -2794,6 +2797,8 @@ en:
import_protocol_notification:
title: "The import process has been successfully completed. You can download original file here: %{link}"
message: "Protocol template:"
import_protocol_notification_error:
title: "We're sorry, but the file import has failed. Please ensure you have a stable internet connection and try again. If the problem persists, please contact support for further assistance."
export:
export_results:
title: "Export results"