-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27c4094
commit f5ad224
Showing
13 changed files
with
234 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@import '../../styles/mixins.scss'; | ||
|
||
.ydb-error-boundary { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: flex-start; | ||
|
||
padding: 20px; | ||
|
||
@include body-2-typography(); | ||
|
||
&__illustration { | ||
width: 230px; | ||
height: 230px; | ||
margin-right: 20px; | ||
} | ||
&__error-title { | ||
margin-top: 44px; | ||
@include lead-typography(); | ||
} | ||
&__error-description { | ||
margin-top: 12px; | ||
} | ||
&__show-details { | ||
margin-top: 8px; | ||
} | ||
&__error-details { | ||
padding: 13px 18px; | ||
|
||
border: 1px solid var(--g-color-line-generic); | ||
background-color: var(--g-color-base-generic-ultralight); | ||
} | ||
&__actions { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 10px; | ||
|
||
margin-top: 20px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type {ReactNode} from 'react'; | ||
import {ErrorBoundary as ErrorBoundaryBase} from 'react-error-boundary'; | ||
import cn from 'bem-cn-lite'; | ||
|
||
import {Button, Disclosure} from '@gravity-ui/uikit'; | ||
|
||
import {registerError} from '../../utils/registerError'; | ||
import {Illustration} from '../Illustration'; | ||
import i18n from './i18n'; | ||
import './ErrorBoundary.scss'; | ||
|
||
const b = cn('ydb-error-boundary'); | ||
|
||
interface ErrorBoundaryProps { | ||
children?: ReactNode; | ||
useRetry?: boolean; | ||
onReportProblem?: (error?: Error) => void; | ||
} | ||
|
||
export const ErrorBoundary = ({children, useRetry = true, onReportProblem}: ErrorBoundaryProps) => { | ||
return ( | ||
<ErrorBoundaryBase | ||
onError={(error, info) => { | ||
registerError(error, info.componentStack, 'error-boundary'); | ||
}} | ||
fallbackRender={({error, resetErrorBoundary}) => { | ||
return ( | ||
<div className={b(null)}> | ||
<Illustration name="error" className={b('illustration')} /> | ||
<div className={b('content')}> | ||
<h2 className={b('error-title')}>{i18n('error-title')}</h2> | ||
<div className={b('error-description')}> | ||
{i18n('error-description')} | ||
</div> | ||
<Disclosure | ||
summary={i18n('show-details')} | ||
className={b('show-details')} | ||
size="m" | ||
> | ||
<pre className={b('error-details')}>{error.stack}</pre> | ||
</Disclosure> | ||
<div className={b('actions')}> | ||
{useRetry && ( | ||
<Button view="outlined" onClick={resetErrorBoundary}> | ||
{i18n('button-reset')} | ||
</Button> | ||
)} | ||
{onReportProblem && ( | ||
<Button view="outlined" onClick={() => onReportProblem(error)}> | ||
{i18n('report-problem')} | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}} | ||
> | ||
{children} | ||
</ErrorBoundaryBase> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"error-title": "Something went wrong", | ||
"error-description": "We have something broken, but don't worry, it won't last long", | ||
"show-details": "Show details", | ||
"report-problem": "Report a problem", | ||
"button-reset": "Try again" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {i18n, Lang} from '../../../utils/i18n'; | ||
|
||
import en from './en.json'; | ||
import ru from './ru.json'; | ||
|
||
const COMPONENT = 'ydb-error-boundary'; | ||
|
||
i18n.registerKeyset(Lang.En, COMPONENT, en); | ||
i18n.registerKeyset(Lang.Ru, COMPONENT, ru); | ||
|
||
export default i18n.keyset(COMPONENT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"error-title": "Что-то пошло не так", | ||
"error-description": "У нас что-то сломалось, но не переживайте, это ненадолго", | ||
"show-details": "Показать детали", | ||
"report-problem": "Сообщить о проблеме", | ||
"button-reset": "Попробовать снова" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function registerError(error: Error, message?: string, type = 'error') { | ||
if (typeof window !== 'undefined' && window.Ya?.Rum) { | ||
window.Ya.Rum.logError( | ||
{ | ||
additional: { | ||
url: window.location.href, | ||
}, | ||
type, | ||
message, | ||
level: window.Ya.Rum.ERROR_LEVEL.ERROR, | ||
}, | ||
error, | ||
); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
} | ||
} |