mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-06 15:40:31 +08:00
Add error handling to actions in protocol controller [SCI-8073] (#5074)
This commit is contained in:
parent
d1f26e1c7b
commit
da31883ac3
3 changed files with 22 additions and 4 deletions
|
@ -425,13 +425,16 @@ var ProtocolsIndex = (function() {
|
|||
}
|
||||
|
||||
function initdeleteDraftModal() {
|
||||
$('.protocols-index').on('click', '#protocol-versions-modal .delete-draft', function(e) {
|
||||
$('.protocols-index').on('click', '#protocol-versions-modal .delete-draft', function() {
|
||||
let url = this.dataset.url;
|
||||
let modal = $('#deleteDraftModal');
|
||||
$('#protocol-versions-modal').modal('hide');
|
||||
modal.modal('show');
|
||||
modal.find('form').attr('action', url);
|
||||
});
|
||||
$('#deleteDraftModal form').on('ajax:error', function(_ev, data) {
|
||||
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
function initProtocolsioModal() {
|
||||
|
|
|
@ -177,6 +177,11 @@ class ProtocolsController < ApplicationController
|
|||
protocol: @protocol.id,
|
||||
version_number: @protocol.version_number)
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:error] = e.message
|
||||
Rails.logger.error e.message
|
||||
raise ActiveRecord::Rollback
|
||||
rescue StandardError => e
|
||||
flash[:error] = I18n.t('errors.general')
|
||||
Rails.logger.error e.message
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
@ -199,7 +204,11 @@ class ProtocolsController < ApplicationController
|
|||
redirect_to protocols_path
|
||||
rescue ActiveRecord::RecordNotDestroyed => e
|
||||
Rails.logger.error e.message
|
||||
render json: { status: 'error' }, status: :unprocessable_entity
|
||||
render json: { message: e.message }, status: :unprocessable_entity
|
||||
raise ActiveRecord::Rollback
|
||||
rescue StandardError => e
|
||||
render json: { message: I18n.t('errors.general') }, status: :unprocessable_entity
|
||||
Rails.logger.error e.message
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
@ -237,7 +246,7 @@ class ProtocolsController < ApplicationController
|
|||
render json: @protocol, serializer: ProtocolSerializer, user: current_user
|
||||
end
|
||||
else
|
||||
format.json { render json: {}, status: :unprocessable_entity }
|
||||
format.json { render json: I18n.t('errors.general'), status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -388,6 +397,8 @@ class ProtocolsController < ApplicationController
|
|||
rescue StandardError => e
|
||||
Rails.logger.error(e.message)
|
||||
Rails.logger.error(e.backtrace.join("\n"))
|
||||
flash[:error] = I18n.t('errors.general')
|
||||
redirect_to protocols_path
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
@ -1105,7 +1116,7 @@ class ProtocolsController < ApplicationController
|
|||
respond_to do |format|
|
||||
if rollbacked
|
||||
format.json do
|
||||
render json: {}, status: :bad_request
|
||||
render json: { message: I18n.t('errors.general') }, status: :unprocessable_entity
|
||||
end
|
||||
else
|
||||
format.json do
|
||||
|
|
|
@ -20,6 +20,10 @@ window.initProtocolComponent = () => {
|
|||
modal.find('form').attr('action', url);
|
||||
});
|
||||
|
||||
$('#deleteDraftModal form').on('ajax:error', function(_ev, data) {
|
||||
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
||||
});
|
||||
|
||||
new Vue({
|
||||
el: '#protocolContainer',
|
||||
components: {
|
||||
|
|
Loading…
Reference in a new issue