-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsod.tsx
More file actions
52 lines (44 loc) · 1.55 KB
/
bsod.tsx
File metadata and controls
52 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**********************************************************************
Copyright (c) Vladimir Davidovich. All rights reserved.
***********************************************************************/
import { PureComponent, type ReactNode } from 'react';
import { TextElement, VisualElement } from './react';
interface BsodProps {
error: Error;
}
export function Bsod({ error }: BsodProps) {
return (
<VisualElement
style-flexGrow-value={1}
style-justifyContent-value="Center"
style-backgroundColor-value={[0, 0, 0, 1]}
style-color-value={[1, 1, 1, 1]}
style-paddingLeft-value-value={16}>
<TextElement style-flexShrink-value={0} style-fontSize-value-value={60}>:(</TextElement>
<TextElement style-flexShrink-value={0} style-fontSize-value-value={20}>{error?.message || error?.toString()}</TextElement>
<TextElement style-flexShrink-value={0} style-whiteSpace-value="Pre" style-color-value={[0.7, 0.7, 0.7, 1]}>{error?.stack}</TextElement>
</VisualElement>
);
}
export class BsodBoundary extends PureComponent<{
children?: ReactNode;
}, {
hasError: boolean;
error: Error;
}> {
static readonly displayName = "BsodBoundary";
state = {
hasError: false,
error: undefined! as Error
};
static getDerivedStateFromError(error: Error) {
const hasError = !error.message.startsWith("Cannot change attachment");
return { hasError, error };
}
render() {
const state = this.state;
if (!state.hasError)
return this.props.children;
return <Bsod error={state.error}></Bsod>;
}
}