Format error before sending it from back-end [SCI-7831]

This commit is contained in:
sboursen-scinote 2023-02-06 13:29:15 +01:00
parent a78f113498
commit c39b660fe3
2 changed files with 7 additions and 2 deletions

View file

@ -195,7 +195,7 @@ function handleFormSubmit(modal) {
HelperModule.flashAlertMsg(data.message, 'success');
},
error: function(data) {
showFormErrors(modal, data.responseJSON.errors);
showFormErrors(modal, data.responseJSON.validation_errors);
},
complete: function() {
animateSpinner(modal, false);

View file

@ -44,7 +44,7 @@ module ProtocolImporters
step
end
rescue StandardError => e
@errors[:protocol] = e.message
@errors[:protocol] = format_error(e)
end
self
@ -56,6 +56,11 @@ module ProtocolImporters
private
def format_error(e)
error_type, *error_message = e.message.split(': ')[1].split(' ')
{error_type.downcase.to_sym => [error_message.join(' ')]}
end
def valid?
unless [@protocol_params, @user, @team].all?
@errors[:invalid_arguments] = {