Skip to content

Commit

Permalink
Improve git hash info error handling in home.js
Browse files Browse the repository at this point in the history
Instead of showing a generic error message alert when an error occurs,
it displays an error message at the same place where the success output
goes.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Sep 20, 2023
1 parent 80865af commit 5e8ec69
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 6 additions & 1 deletion js/src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,16 @@ $(document).on('submit', 'form', AJAX.requestHandler);
* Gracefully handle fatal server errors
* (e.g: 500 - Internal server error)
*/
$(document).on('ajaxError', function (event, request) {
$(document).on('ajaxError', function (event, request, settings) {
if (AJAX.debug) {
// eslint-disable-next-line no-console
console.log('AJAX error: status=' + request.status + ', text=' + request.statusText);
}

if (settings.url.includes('/git-revision')) {
return;
}

// Don't handle aborted requests
if (request.status !== 0 || request.statusText !== 'abort') {
var details = '';
Expand Down
14 changes: 8 additions & 6 deletions js/src/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ const GitInfo = {
'server': CommonParams.get('server'),
'ajax_request': true,
'no_debug': true
},
function (data) {
if (typeof data !== 'undefined' && data.success === true) {
$(data.message).insertAfter('#li_pma_version');
}
}
);
).done(function (data) {
if (typeof data !== 'undefined' && data.success === true) {
$(data.message).insertAfter('#li_pma_version');
}
}).fail(function () {
const gitHashInfoLi = '<li id="li_pma_version_git" class="list-group-item">' + window.Messages.errorLoadingGitInformation + '</li>';
$(gitHashInfoLi).insertAfter('#li_pma_version');
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ private function setMessages(): void
/* l10n: Latest available phpMyAdmin version */
'strLatestAvailable' => __(', latest stable version:'),
'strUpToDate' => __('up to date'),
'errorLoadingGitInformation' => __('There was an error in loading the Git information.'),

/* Error Reporting */
'strErrorOccurred' => __('A fatal JavaScript error has occurred. Would you like to send an error report?'),
Expand Down

0 comments on commit 5e8ec69

Please sign in to comment.