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:
parent
450a299bae
commit
bf0646c307
|
@ -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 couldn’t 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 = () => {
|
const install = () => {
|
||||||
recordEvent( 'marketplace_product_install_button_clicked', {
|
recordEvent( 'marketplace_product_install_button_clicked', {
|
||||||
product_zip_slug: props.subscription.zip_slug,
|
product_zip_slug: props.subscription.zip_slug,
|
||||||
|
@ -90,71 +132,26 @@ export default function Install( props: InstallProps ) {
|
||||||
props.onSuccess();
|
props.onSuccess();
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.catch( ( error ) => {
|
.catch( handleInstallError );
|
||||||
loadSubscriptions( false ).then( () => {
|
} else {
|
||||||
let errorMessage = sprintf(
|
getInstallUrl( props.subscription )
|
||||||
// translators: %s is the product name.
|
.then( ( url: string ) => {
|
||||||
__( '%s couldn’t be installed.', 'woocommerce' ),
|
recordEvent( 'marketplace_product_install_url', {
|
||||||
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_zip_slug: props.subscription.zip_slug,
|
||||||
product_id: props.subscription.product_id,
|
product_id: props.subscription.product_id,
|
||||||
product_current_version: props.subscription.version,
|
product_current_version: props.subscription.version,
|
||||||
error_message: error?.data?.message,
|
product_install_url: url,
|
||||||
} );
|
} );
|
||||||
} );
|
|
||||||
} else {
|
|
||||||
getInstallUrl( props.subscription ).then( ( url: string ) => {
|
|
||||||
recordEvent( 'marketplace_product_install_url', {
|
|
||||||
product_zip_slug: props.subscription.zip_slug,
|
|
||||||
product_id: props.subscription.product_id,
|
|
||||||
product_current_version: props.subscription.version,
|
|
||||||
product_install_url: url,
|
|
||||||
} );
|
|
||||||
|
|
||||||
stopInstall();
|
stopInstall();
|
||||||
|
|
||||||
if ( url ) {
|
if ( url ) {
|
||||||
window.open( url, '_self' );
|
window.open( url, '_self' );
|
||||||
} else {
|
} else {
|
||||||
addNotice(
|
throw new Error();
|
||||||
props.subscription.product_key,
|
}
|
||||||
sprintf(
|
} )
|
||||||
// translators: %s is the product name.
|
.catch( handleInstallError );
|
||||||
__(
|
|
||||||
'%s couldn’t be installed. Please install the product manually.',
|
|
||||||
'woocommerce'
|
|
||||||
),
|
|
||||||
props.subscription.product_name
|
|
||||||
),
|
|
||||||
NoticeStatus.Error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: enhancement
|
||||||
|
|
||||||
|
Introduce error handling on the in-app my subscriptions page
|
Loading…
Reference in New Issue