mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
show error when mount() fails in SwitchView
This commit is contained in:
parent
449262e3c1
commit
e0799181d9
@ -1,3 +1,5 @@
|
||||
import {errorToDOM} from "./error.js";
|
||||
|
||||
export class SwitchView {
|
||||
constructor(defaultView) {
|
||||
this._childView = defaultView;
|
||||
@ -23,7 +25,12 @@ export class SwitchView {
|
||||
const oldRoot = this.root();
|
||||
this._childView.unmount();
|
||||
this._childView = newView;
|
||||
const newRoot = this._childView.mount();
|
||||
let newRoot;
|
||||
try {
|
||||
newRoot = this._childView.mount();
|
||||
} catch (err) {
|
||||
newRoot = errorToDOM(err);
|
||||
}
|
||||
const parent = oldRoot.parentElement;
|
||||
if (parent) {
|
||||
parent.replaceChild(newRoot, oldRoot);
|
||||
|
12
src/ui/web/general/error.js
Normal file
12
src/ui/web/general/error.js
Normal file
@ -0,0 +1,12 @@
|
||||
import {tag} from "./html.js";
|
||||
|
||||
export function errorToDOM(error) {
|
||||
const stack = new Error().stack;
|
||||
const callee = stack.split("\n")[1];
|
||||
return tag.div([
|
||||
tag.h2("Something went wrong…"),
|
||||
tag.h3(error.message),
|
||||
tag.p(`This occurred while running ${callee}.`),
|
||||
tag.pre(error.stack),
|
||||
]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user