Catches modulo import errors and display error messages on screen.

This commit is contained in:
mateuswetah 2022-06-10 17:14:02 -03:00
parent 1846720944
commit 1b2b79ec23
2 changed files with 27 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import * as conditioner from 'conditioner-core/conditioner-core.esm';
const { __ } = wp.i18n;
// Updates Webpack public path based on plugin folder URL, using variable obtained from server side.
__webpack_public_path__ = tainacan_plugin.plugin_dir_url + 'assets/js/';
@ -67,7 +68,17 @@ performWhenDocumentIsLoaded(() => {
/* webpackMode: "lazy" */
/* webpackInclude: /theme\.js$/ */
/* webpackChunkName: "tainacan-chunks-" */
`${name}`)
`${name}`
)
.catch((error) => {
let moduleElements = document.querySelectorAll('[data-module]');
moduleElements.forEach((moduleElement) => {
moduleElement.innerHTML = `<p style="font-size: 1rem;"><strong>` + __( 'An error ocurred while loading this Tainacan component. Please reload your page (CTRL+SHIFT+R).', 'tainacan') + `</strong></p>`;
});
console.warn( __( 'An error ocurred while loading some Tainacan components. Please reload your page (CTRL+SHIFT+R).', 'tainacan') );
console.warn( __( 'Clearing the cache may help. It is possible that the browser or server are retaining old information that are preventing Tainacan components to be loading correctly.', 'tainacan') );
console.error(error);
})
});
// lets go!

View File

@ -1,4 +1,5 @@
import * as conditioner from 'conditioner-core/conditioner-core.esm';
const { __ } = wp.i18n;
// Updates Webpack public path based on plugin folder URL, using variable obtained from server side.
__webpack_public_path__ = tainacan_plugin.plugin_dir_url + 'assets/js/';
@ -28,7 +29,20 @@ performWhenDocumentIsLoaded(() => {
/* webpackMode: "lazy" */
/* webpackInclude: /main\.js$/ */
/* webpackChunkName: "tainacan-chunks-" */
`${name}`)
`${name}`
)
.catch((error) => {
let moduleElements = document.querySelectorAll('[data-module]');
moduleElements.forEach((moduleElement) => {
moduleElement.innerHTML = `<div style="padding: 2rem; margin: 1rem auto; text-align: center;">
<p style="font-size: 1.25rem;"><strong>` + __( 'An error ocurred while loading Tainacan. Please reload your page (CTRL+SHIFT+R).', 'tainacan') + `</strong></p>
<p style="font-size: 1rem">` + __( 'Clearing the cache may help. It is possible that the browser or server are retaining old information that are preventing the page to be loading correctly.', 'tainacan') + `</p>
</div>`;
});
console.warn(__( 'An error ocurred while loading Tainacan. Please reload your page (CTRL+SHIFT+R).', 'tainacan'));
console.warn(__( 'Clearing the cache may help. It is possible that the browser or server are retaining old information that are preventing the page to be loading correctly.', 'tainacan'));
console.error(error);
})
});
// lets go!