The generic error handler callback can now display non-JSON responses (#836).

This commit is contained in:
Alex Tselegidis 2020-08-15 15:26:26 +03:00
parent 4f1c39b564
commit 8f1e82019f

View file

@ -301,7 +301,13 @@ window.GeneralFunctions = window.GeneralFunctions || {};
exports.ajaxFailureHandler = function (jqXHR, textStatus, errorThrown) {
console.error('Unexpected HTTP Error: ', jqXHR, textStatus, errorThrown);
var response = JSON.parse(jqXHR.responseText);
var response;
try {
response = JSON.parse(jqXHR.responseText); // JSON response
} catch(error) {
response = { message: jqXHR.responseText }; // String response
}
if (!response) {
return;
@ -311,7 +317,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
$('<div/>', {
'class': 'well',
'text': response.message
'html': response.message || '→ No error information provided.'
})
.appendTo('#message_box');
};