-
Notifications
You must be signed in to change notification settings - Fork 12
/
ErrorUI.jsx
47 lines (45 loc) · 1.79 KB
/
ErrorUI.jsx
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
import React from 'react';
import { Divider, Collapse, Chip } from '@mui/material'
import {ArrowRight as RightIcon, ArrowDropDown as DownIcon} from '@mui/icons-material'
import { get, isObject } from 'lodash';
import { ERROR_RED } from '../../common/constants';
const ErrorUI = ({header, message, error, errorInfo}) => {
const [open, setOpen] = React.useState(false)
const icon = open ?
<DownIcon style={{color: ERROR_RED}} /> :
<RightIcon style={{color: ERROR_RED}} />;
const errorDetails = get(errorInfo, 'componentStack') ? errorInfo.componentStack : JSON.stringify(errorInfo, undefined, 2);
const errorMsg = isObject(error) ? error.toString() : error;
return (
<React.Fragment>
<div className='not-found'>
<div className='flex-vertical-center'>
<h1>{header}</h1>
<Divider orientation="vertical" />
<div className='not-found-text'>
<h2 dangerouslySetInnerHTML={{__html: message}} />
</div>
</div>
{
errorMsg &&
<div style={{color: ERROR_RED, display: 'inline-block', textAlign: 'center', marginTop: '15px'}}>
<Chip
className='error-chip no-border'
variant='outlined'
icon={icon}
label='Error Details'
onClick={() => setOpen(!open)}
/>
<Collapse className='collapsed-error-details' in={open} timeout='auto' style={{background: 'rgba(244,67,54, 0.1)', padding: '10px', textAlign: 'left'}}>
<h4 style={{marginBottom: '-15px', marginTop: '0px'}}>{errorMsg}</h4>
<pre style={{whiteSpace: 'pre-wrap', marginTop: '2px'}}>
{errorDetails}
</pre>
</Collapse>
</div>
}
</div>
</React.Fragment>
)
}
export default ErrorUI;