DEV: Catch errors in theme/plugin onPageChange handlers (#24784)

This makes the errors easier for admins to identify/resolve, and also prevents failures from affecting core functionality.
This commit is contained in:
David Taylor 2023-12-08 10:01:37 +00:00 committed by GitHub
parent dcd81d56c0
commit efbe5b7dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -799,7 +799,8 @@ class PluginApi {
```
**/
onPageChange(fn) {
this.onAppEvent("page:changed", (data) => fn(data.url, data.title));
const callback = wrapWithErrorHandler(fn, "broken_page_change_alert");
this.onAppEvent("page:changed", (data) => callback(data.url, data.title));
}
/**

View File

@ -220,6 +220,7 @@ en:
only_admins: "(this message is only shown to site administrators)"
broken_decorator_alert: "Posts may not display correctly because one of the post content decorators on your site raised an error."
broken_page_change_alert: "An onPageChange handler raised an error. Check the browser developer tools for more information."
broken_plugin_alert: "Caused by plugin '%{name}'"