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

67 lines
2 KiB
React
Raw Permalink Normal View History

2018-09-26 19:48:07 +02:00
// @flow
2019-03-18 06:09:50 +01:00
import { Lbryio } from 'lbryinc';
import React from 'react';
2019-03-18 06:09:50 +01:00
import { Modal } from 'modal/modal';
2017-04-07 07:15:22 +02:00
2018-09-26 19:48:07 +02:00
type Props = {
error: string | { message: string },
closeModal: () => void,
};
class ModalError extends React.PureComponent<Props> {
2019-03-18 06:09:50 +01: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 skipLog =
errorMessage.startsWith('Failed to download') ||
errorMessage.endsWith('Uploading the same file from multiple tabs or windows is not allowed.');
if (process.env.NODE_ENV === 'production' && !skipLog) {
Lbryio.call('event', 'desktop_error', { error_message: JSON.stringify(error) });
2019-04-24 16:02:08 +02:00
}
2019-03-18 06:09:50 +01:00
}
2017-04-07 07:15:22 +02:00
render() {
2017-09-08 05:15:05 +02:00
const { closeModal, error } = this.props;
2017-04-07 07:15:22 +02:00
const errorObj = typeof error === 'string' ? { message: error } : error;
2017-05-24 23:53:03 +02:00
2018-04-18 06:03:01 +02:00
const errorKeyLabels = {
connectionString: __('API connection string'),
method: __('Method'),
params: __('Parameters'),
code: __('Error code'),
message: __('Error message'),
data: __('Error data'),
2017-06-06 23:19:12 +02:00
};
2017-06-06 06:21:55 +02:00
2017-06-06 23:19:12 +02: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 06:03:01 +02:00
const label = errorKeyLabels[key];
2017-06-06 23:19:12 +02:00
errorInfoList.push(
2017-11-24 15:31:05 +01:00
<li key={key}>
2018-09-26 19:48:07 +02:00
<strong>{label}</strong>: {val}
2017-11-24 15:31:05 +01:00
</li>
2017-06-06 23:19:12 +02:00
);
2017-04-07 07:15:22 +02:00
}
2018-09-26 19:48:07 +02:00
2017-06-06 23:19:12 +02:00
return (
2019-05-07 23:38:29 +02:00
<Modal isOpen contentLabel={__('Error')} title={__('Error')} className="error-modal" onConfirmed={closeModal}>
2019-07-21 23:31:22 +02:00
<p>
{__(
"We're sorry that Odysee has encountered an error. Please try again or reach out to hello@odysee.com with detailed information."
2019-07-21 23:31:22 +02:00
)}
</p>
2020-02-24 02:31:13 +01:00
<ul className="error-modal__error-list ul--no-style">{errorInfoList}</ul>
2019-03-18 06:09:50 +01:00
</Modal>
2017-06-06 23:19:12 +02:00
);
2017-04-07 07:15:22 +02:00
}
}
2017-07-02 20:23:38 +02:00
export default ModalError;