Always show CSRF error message for Ajax

This commit is contained in:
Sebastian Serth
2021-11-23 01:37:50 +01:00
parent eec6d64e8c
commit 18f05db138
3 changed files with 13 additions and 7 deletions

View File

@ -7,11 +7,12 @@ CodeOceanEditorAJAX = {
}, },
ajaxError: function(response) { ajaxError: function(response) {
var message = ((response || {}).responseJSON || {}).message || ''; const responseJSON = ((response || {}).responseJSON || {});
const message = responseJSON.message || responseJSON.error || '';
$.flash.danger({ $.flash.danger({
text: message.length > 0 ? message : $('#flash').data('message-failure'), text: message.length > 0 ? message : $('#flash').data('message-failure'),
showPermanent: response.status === 422, showPermanent: response.status === 422,
}); });
} }
}; };

View File

@ -110,11 +110,14 @@ $(document).on('turbolinks:load', function () {
} }
} }
var ajaxError = function (error) { var ajaxError = function (response) {
const responseJSON = ((response || {}).responseJSON || {});
const message = responseJSON.message || responseJSON.error || '';
$.flash.danger({ $.flash.danger({
text: $('#flash').data('message-failure') text: message.length > 0 ? message : $('#flash').data('message-failure'),
showPermanent: response.status === 422,
}); });
Sentry.captureException(JSON.stringify(error));
}; };
var buildCheckboxes = function () { var buildCheckboxes = function () {

View File

@ -469,9 +469,11 @@ javascript:
} }
function ajaxError(response) { function ajaxError(response) {
var message = ((response || {}).responseJSON || {}).message || ''; const responseJSON = ((response || {}).responseJSON || {});
const message = responseJSON.message || responseJSON.error || '';
$.flash.danger({ $.flash.danger({
text: message.length > 0 ? message : $('#flash').data('message-failure') text: message.length > 0 ? message : $('#flash').data('message-failure'),
showPermanent: response.status === 422,
}); });
} }