Skip to content

Commit

Permalink
[fixup] better error handling in service worker and popup
Browse files Browse the repository at this point in the history
  • Loading branch information
nxmatic committed Jul 14, 2024
1 parent b57acc3 commit 5a27bdc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/main/server-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ This extension is only compatible with Nuxeo Platform servers.
this.runtimeInfo = undefined;
this.serverUrl = undefined;
const notification = this.notifyError(cause);
throw this.connectionErrorOf(`Cannot establish connection with ${serverUrl}`, notification);
return Promise.reject(this.connectionErrorOf(`Cannot establish connection with ${serverUrl}`, notification));
}));
}

Expand Down Expand Up @@ -257,7 +257,7 @@ This extension is only compatible with Nuxeo Platform servers.
.asTabInfo()
.then((tabInfo) => {
const serverUrl = this.serverUrlOf(tabInfo.url);
const attemptReconnect = () => this.connect(serverUrl, tabInfo, connectionOptions).then(() => this.nuxeo);
const attemptConnection = () => this.connect(serverUrl, tabInfo, connectionOptions).then(() => this.nuxeo);
const urlEquals = (url1, url2) => url1.protocol === url2.protocol &&
url1.hostname === url2.hostname &&
url1.port === url2.port &&
Expand All @@ -269,11 +269,11 @@ This extension is only compatible with Nuxeo Platform servers.
.then(() => this.nuxeo) // Connection is valid
.catch((error) => {
console.error('Failed to refetch the user, connection might be lost.', error);
return attemptReconnect();
return attemptConnection();
});
}
// Not connected or different server, attempt to connect
return attemptReconnect();
return attemptConnection();
});
}

Expand Down
21 changes: 11 additions & 10 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
// process the page, should split this in multiple functions
// eslint-disable-next-line no-unused-vars
.then(({ connectUrl, connectCredentials, cookiesGranted }) => {
// bind the fields with the js worker
// bind the fields with the js worker
const pendingPromises = [];

pendingPromises.push(
worker.developmentMode.isEnabled().then((isEnabled) => {
// Assuming isEnabled is already determined
// Assuming isEnabled is already determined
const shouldBeReadOnly = !isEnabled;
// Toggle class for read-only styling
$('.server-main #options').toggleClass(
Expand Down Expand Up @@ -415,8 +415,8 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
permissions,
error
);
// Handle the error appropriately in your extension
// For example, you might want to inform the user that the permissions cannot be modified
// Handle the error appropriately in your extension
// For example, you might want to inform the user that the permissions cannot be modified
});
});
})
Expand Down Expand Up @@ -565,7 +565,7 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
// eslint-disable-next-line no-shadow
.then((registration) => {
const {
// eslint-disable-next-line no-shadow, no-unused-vars
// eslint-disable-next-line no-shadow, no-unused-vars
serverUrl: serverLocation,
connectUrl: connectLocation,
connectSubscription,
Expand Down Expand Up @@ -835,7 +835,7 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
};

$('#restart-button').on('click', () => {
// Function to show confirmation dialog
// Function to show confirmation dialog
const confirmRestart = () => Swal.fire({
title: 'Warning!',
text: `You have administrator privileges but the server is not in development mode.
Expand Down Expand Up @@ -878,7 +878,7 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
})
.then((html) => {
$('body').html(html);
// If the loaded page has its own scripts, you might need to reinitialize them here
// If the loaded page has its own scripts, you might need to reinitialize them here
})
.catch((error) => {
console.error('Error loading page:', error);
Expand All @@ -892,7 +892,7 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {

// Handle click events for the radio buttons
$(document).on('click', '#reindex-repo, #reindex-nxql', function () {
// Toggle 'active' class for the clicked button
// Toggle 'active' class for the clicked button
$(this).toggleClass('active');

// If the other button is active, remove its 'active' class
Expand Down Expand Up @@ -974,7 +974,7 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
$('#loading-gif').css({ display: 'inline' });
$('#search').css('text-indent', '23px');
if (event.keyCode === 13) {
// prevent submit on enter
// prevent submit on enter
event.preventDefault();
}
});
Expand Down Expand Up @@ -1090,7 +1090,8 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
return Promise.all(pendingPromises)
.then(() => worker)
.finally(() => stopLoading());
})))
}))
.catch((cause) => stopLoading(cause)))
.catch((cause) => stopLoading(cause));
}

Expand Down

0 comments on commit 5a27bdc

Please sign in to comment.