2018-09-26 19:48:07 +02:00
|
|
|
// @flow
|
2019-03-18 06:09:50 +01:00
|
|
|
import { Lbryio } from 'lbryinc';
|
2017-12-21 22:08:54 +01:00
|
|
|
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() {
|
2019-07-23 22:13:06 +02:00
|
|
|
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 16:02:08 +02:00
|
|
|
}
|
2019-03-18 06:09:50 +01:00
|
|
|
}
|
2019-07-23 22:13:06 +02: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
|
|
|
|
2017-12-21 22:08:54 +01: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 = {
|
2017-12-21 22:08:54 +01:00
|
|
|
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 = [];
|
2017-12-21 22:08:54 +01:00
|
|
|
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>
|
|
|
|
{__(
|
2021-11-03 20:47:19 +01:00
|
|
|
"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;
|