mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 10:02:33 +03:00
Add global JS error handling for HTTP requests.
This commit is contained in:
parent
7fdc5cf7fe
commit
ab7ba646a8
1 changed files with 32 additions and 0 deletions
|
@ -14,6 +14,38 @@
|
|||
* This script should be loaded before the other modules in order to define the global application namespace.
|
||||
*/
|
||||
window.App = (function () {
|
||||
function onAjaxError(event, jqXHR, textStatus, errorThrown) {
|
||||
console.error('Unexpected HTTP Error: ', jqXHR, textStatus, errorThrown);
|
||||
|
||||
let response;
|
||||
|
||||
try {
|
||||
response = JSON.parse(jqXHR.responseText); // JSON response
|
||||
} catch (error) {
|
||||
response = {message: jqXHR.responseText}; // String response
|
||||
}
|
||||
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (App.Utils.Message) {
|
||||
App.Utils.Message.show(lang('unexpected_issues'), lang('unexpected_issues_message'));
|
||||
|
||||
$('<div/>', {
|
||||
'class': 'card',
|
||||
'html': [
|
||||
$('<div/>', {
|
||||
'class': 'card-body',
|
||||
'html': response.message || '→ No error information provided.'
|
||||
})
|
||||
]
|
||||
}).appendTo('#message-box');
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ajaxError(onAjaxError);
|
||||
|
||||
return {
|
||||
Components: {},
|
||||
Http: {},
|
||||
|
|
Loading…
Reference in a new issue