lbry-desktop/ui/modal/modalError/view.jsx

65 lines
1.9 KiB
React
Raw Normal View History

2018-09-26 13:48:07 -04:00
// @flow
2019-03-18 01:09:50 -04:00
import { Lbryio } from 'lbryinc';
import React from 'react';
2019-03-18 01:09:50 -04:00
import { Modal } from 'modal/modal';
2017-04-07 12:15:22 +07:00
2018-09-26 13:48:07 -04:00
type Props = {
error: string | { message: string },
closeModal: () => void,
};
class ModalError extends React.PureComponent<Props> {
2019-03-18 01:09:50 -04:00
componentDidMount() {
const { error } = this.props;
// Yuck
// https://github.com/lbryio/lbry-sdk/issues/1118
// The sdk logs failed downloads, they happen so often that it's mostly noise in the desktop logs
const errorMessage = typeof error === 'string' ? error : error.message;
const failedToDownloadError = errorMessage.startsWith('Failed to download');
if (process.env.NODE_ENV === 'production' && !failedToDownloadError) {
Lbryio.call('event', 'desktop_error', { error_message: JSON.stringify(error) });
2019-04-24 10:02:08 -04:00
}
2019-03-18 01:09:50 -04:00
}
2017-04-07 12:15:22 +07:00
render() {
2017-09-07 23:15:05 -04:00
const { closeModal, error } = this.props;
2017-04-07 12:15:22 +07:00
const errorObj = typeof error === 'string' ? { message: error } : error;
2017-05-24 17:53:03 -04:00
2018-04-18 00:03:01 -04:00
const errorKeyLabels = {
connectionString: __('API connection string'),
method: __('Method'),
params: __('Parameters'),
code: __('Error code'),
message: __('Error message'),
data: __('Error data'),
2017-06-06 17:19:12 -04:00
};
2017-06-05 21:21:55 -07:00
2017-06-06 17:19:12 -04:00
const errorInfoList = [];
for (const key of Object.keys(errorObj)) {
const val = typeof errorObj[key] === 'string' ? errorObj[key] : JSON.stringify(errorObj[key]);
2018-04-18 00:03:01 -04:00
const label = errorKeyLabels[key];
2017-06-06 17:19:12 -04:00
errorInfoList.push(
2017-11-24 11:31:05 -03:00
<li key={key}>
2018-09-26 13:48:07 -04:00
<strong>{label}</strong>: {val}
2017-11-24 11:31:05 -03:00
</li>
2017-06-06 17:19:12 -04:00
);
2017-04-07 12:15:22 +07:00
}
2018-09-26 13:48:07 -04:00
2017-06-06 17:19:12 -04:00
return (
2019-05-07 17:38:29 -04:00
<Modal isOpen contentLabel={__('Error')} title={__('Error')} className="error-modal" onConfirmed={closeModal}>
2019-07-21 17:31:22 -04:00
<p>
{__(
"We're sorry that LBRY has encountered an error. This has been reported and we will investigate the problem."
)}
</p>
<ul className="error-modal__error-list">{errorInfoList}</ul>
2019-03-18 01:09:50 -04:00
</Modal>
2017-06-06 17:19:12 -04:00
);
2017-04-07 12:15:22 +07:00
}
}
2017-07-02 14:23:38 -04:00
export default ModalError;