Add error handling when the call to 'install-url' endpoint fails (#51298)

* Add error handling when the call to 'install-url' endpoint fails

* Changelog

* Ignore any explicitly

* Move the function below to address lint

* Change 'Try again' to a href, suggesting to download and install manually

* Lint
This commit is contained in:
Boro Sitnikovski 2024-09-16 16:57:05 +02:00 committed by GitHub
parent 450a299bae
commit bf0646c307
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 59 deletions

View File

@ -51,6 +51,48 @@ export default function Install( props: InstallProps ) {
);
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleInstallError = ( error: any ) => {
loadSubscriptions( false ).then( () => {
let errorMessage = sprintf(
// translators: %s is the product name.
__( '%s couldnt be installed.', 'woocommerce' ),
props.subscription.product_name
);
if ( error?.success === false && error?.data.message ) {
errorMessage += ' ' + error.data.message;
}
addNotice(
props.subscription.product_key,
errorMessage,
NoticeStatus.Error,
{
actions: [
{
label: __(
'Download and install manually',
'woocommerce'
),
url: 'https://woocommerce.com/my-account/downloads/',
},
],
}
);
stopInstall();
if ( props.onError ) {
props.onError();
}
} );
recordEvent( 'marketplace_product_install_failed', {
product_zip_slug: props.subscription.zip_slug,
product_id: props.subscription.product_id,
product_current_version: props.subscription.version,
error_message: error?.data?.message,
} );
};
const install = () => {
recordEvent( 'marketplace_product_install_button_clicked', {
product_zip_slug: props.subscription.zip_slug,
@ -90,45 +132,10 @@ export default function Install( props: InstallProps ) {
props.onSuccess();
}
} )
.catch( ( error ) => {
loadSubscriptions( false ).then( () => {
let errorMessage = sprintf(
// translators: %s is the product name.
__( '%s couldnt be installed.', 'woocommerce' ),
props.subscription.product_name
);
if ( error?.success === false && error?.data.message ) {
errorMessage += ' ' + error.data.message;
}
addNotice(
props.subscription.product_key,
errorMessage,
NoticeStatus.Error,
{
actions: [
{
label: __( 'Try again', 'woocommerce' ),
onClick: install,
},
],
}
);
stopInstall();
if ( props.onError ) {
props.onError();
}
} );
recordEvent( 'marketplace_product_install_failed', {
product_zip_slug: props.subscription.zip_slug,
product_id: props.subscription.product_id,
product_current_version: props.subscription.version,
error_message: error?.data?.message,
} );
} );
.catch( handleInstallError );
} else {
getInstallUrl( props.subscription ).then( ( url: string ) => {
getInstallUrl( props.subscription )
.then( ( url: string ) => {
recordEvent( 'marketplace_product_install_url', {
product_zip_slug: props.subscription.zip_slug,
product_id: props.subscription.product_id,
@ -141,20 +148,10 @@ export default function Install( props: InstallProps ) {
if ( url ) {
window.open( url, '_self' );
} else {
addNotice(
props.subscription.product_key,
sprintf(
// translators: %s is the product name.
__(
'%s couldnt be installed. Please install the product manually.',
'woocommerce'
),
props.subscription.product_name
),
NoticeStatus.Error
);
throw new Error();
}
} );
} )
.catch( handleInstallError );
}
};

View File

@ -0,0 +1,4 @@
Significance: patch
Type: enhancement
Introduce error handling on the in-app my subscriptions page