Show error popup if extension update fails

58ac7464426c4323a2f5af5cc47885dca17a32b5

ceruleandeep <deep@cerulean.navy>

1 files changed, +13 -3Ignore whitespace
public/scripts/extensions.js+13 -3
@@ -770,7 +770,7 @@ async function showExtensionsDetails() {
770770
771/**771/**
772 * Handles the click event for the update button of an extension.772 * Handles the click event for the update button of an extension.
773 * This function makes a POST request to '/update_extension' with the extension's name.773 * This function makes a POST request to '/api/extensions/update' with the extension's name.
774 * If the extension is already up to date, it displays a success message.774 * If the extension is already up to date, it displays a success message.
775 * If the extension is not up to date, it updates the extension and displays a success message with the new commit hash.775 * If the extension is not up to date, it updates the extension and displays a success message with the new commit hash.
776 */776 */
@@ -783,8 +783,11 @@ async function onUpdateClick() {
783 return;783 return;
784 }784 }
785785
786 $(this).find('i').addClass('fa-spin');786 const icon = $(this).find('i');
787 icon.addClass('fa-spin');
787 await updateExtension(extensionName, false);788 await updateExtension(extensionName, false);
789 // updateExtension eats the error, but we can at least stop the spinner
790 icon.removeClass('fa-spin');
788}791}
789792
790/**793/**
@@ -803,10 +806,17 @@ async function updateExtension(extensionName, quiet) {
803 }),806 }),
804 });807 });
805808
809 if (!response.ok) {
810 const text = await response.text();
811 toastr.error(text || response.statusText, t`Extension update failed`, { timeOut: 5000 });
812 console.error('Extension update failed', response.status, response.statusText, text);
813 return;
814 }
815
806 const data = await response.json();816 const data = await response.json();
807817
808 if (!quiet) {818 if (!quiet) {
809 showExtensionsDetails();819 await showExtensionsDetails();
810 }820 }
811821
812 if (data.isUpToDate) {822 if (data.isUpToDate) {