Commit 3185bf1b authored by Robert Knight's avatar Robert Knight

Move launch error rendering into a function

This prevents a warning from Rollup about use of `this` outside a class
or (non-arrow) function in development builds, due to the way Babel
compiles JSX expressions [1]. Moving top-level code into a function is
also useful in case we ever want to write tests for it.

[1] https://github.com/babel/babel/issues/9149
parent d65b65b3
......@@ -186,6 +186,20 @@ function startApp(config, appEl) {
);
}
/**
* @param {Error} error
* @param {HTMLElement} appEl
*/
function reportLaunchError(error, appEl) {
// Report error. In the sidebar the console log is the only notice the user
// gets because the sidebar does not appear at all if the app fails to start.
console.error('Failed to start Hypothesis client: ', error);
// For apps where the UI is visible (eg. notebook, single-annotation view),
// show an error notice.
render(<LaunchErrorPanel error={error} />, appEl);
}
const appEl = /** @type {HTMLElement} */ (
document.querySelector('hypothesis-app')
);
......@@ -197,12 +211,4 @@ fetchConfig(appConfig)
.then(config => {
startApp(config, appEl);
})
.catch(err => {
// Report error. In the sidebar the console log is the only notice the user
// gets because the sidebar does not appear at all if the app fails to start.
console.error('Failed to start Hypothesis client: ', err);
// For apps where the UI is visible (eg. notebook, single-annotation view),
// show an error notice.
render(<LaunchErrorPanel error={err} />, appEl);
});
.catch(err => reportLaunchError(err, appEl));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment