Commit 1b06bdee by Ari Rizzitano Committed by GitHub

Merge pull request #14083 from edx/fix-unformatted-403

fix unformatted html in studio error response
parents 7d791ab9 311e6d7f
...@@ -25,23 +25,24 @@ ...@@ -25,23 +25,24 @@
dataType: 'json' dataType: 'json'
}); });
$(document).ajaxError(function(event, jqXHR, ajaxSettings) { $(document).ajaxError(function(event, jqXHR, ajaxSettings) {
var message, msg; var msg, contentType,
message = gettext('This may be happening because of an error with our server or your internet connection. Try refreshing the page or making sure you are online.'); // eslint-disable-line max-len
if (ajaxSettings.notifyOnError === false) { if (ajaxSettings.notifyOnError === false) {
return; return;
} }
if (jqXHR.responseText) { contentType = jqXHR.getResponseHeader('content-type');
try { if (contentType && contentType.indexOf('json') > -1 && jqXHR.responseText) {
message = JSON.parse(jqXHR.responseText).error; message = JSON.parse(jqXHR.responseText).error;
} catch (error) {
message = str.truncate(jqXHR.responseText, 300);
}
} else {
message = gettext('This may be happening because of an error with our server or your internet connection. Try refreshing the page or making sure you are online.'); // eslint-disable-line max-len
} }
msg = new NotificationView.Error({ msg = new NotificationView.Error({
'title': gettext("Studio's having trouble saving your work"), 'title': gettext("Studio's having trouble saving your work"),
'message': message 'message': message
}); });
console.log('Studio AJAX Error', { // eslint-disable-line no-console
url: event.currentTarget.URL,
response: jqXHR.responseText,
status: jqXHR.status
});
return msg.show(); return msg.show();
}); });
$.postJSON = function(url, data, callback) { $.postJSON = function(url, data, callback) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment