2019-03-07 22:46:15 +01:00
|
|
|
// @flow
|
2019-03-15 17:37:56 +01:00
|
|
|
import { Lbryio } from 'lbryinc';
|
2019-03-07 22:46:15 +01:00
|
|
|
import * as React from 'react';
|
|
|
|
import Yrbl from 'component/yrbl';
|
|
|
|
import Button from 'component/button';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
children: React.Node,
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
hasError: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class ErrorBoundary extends React.Component<Props, State> {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = { hasError: false };
|
|
|
|
}
|
|
|
|
|
|
|
|
static getDerivedStateFromError() {
|
|
|
|
return { hasError: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidCatch(error: { stack: string }) {
|
|
|
|
declare var app: { env: string };
|
|
|
|
|
|
|
|
if (app.env === 'production') {
|
2019-03-15 17:37:56 +01:00
|
|
|
Lbryio.call('event', 'desktop_error', { error_message: error.stack });
|
2019-03-07 22:46:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-03-08 20:20:17 +01:00
|
|
|
if (this.state.hasError) {
|
2019-03-07 22:46:15 +01:00
|
|
|
return (
|
|
|
|
<div className="load-screen">
|
|
|
|
<Yrbl
|
|
|
|
type="sad"
|
|
|
|
title={__('Aw shucks!')}
|
|
|
|
subtitle={
|
|
|
|
<div>
|
|
|
|
<p>
|
|
|
|
{__("There was an error. It's been reported and will be fixed")}. {__('Try')}{' '}
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
className="load-screen__button"
|
|
|
|
label={__('refreshing the app')}
|
|
|
|
onClick={() => window.location.reload()}
|
|
|
|
/>{' '}
|
|
|
|
{__('to fix it')}.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
}
|