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
|
|
|
|
2022-01-06 08:26:03 +01:00
|
|
|
// Note: It accepts an object for 'error', but never pass Error itself as Error
|
|
|
|
// cannot be stringified (unless the code below is updated to handle that).
|
|
|
|
|
2018-09-26 19:48:07 +02:00
|
|
|
type Props = {
|
2022-01-06 08:26:03 +01:00
|
|
|
error: string | { message: string, cause?: any },
|
2018-09-26 19:48:07 +02:00
|
|
|
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
|
2022-01-06 08:26:03 +01:00
|
|
|
let errorMessage = typeof error === 'string' ? error : error.message;
|
2021-11-23 02:30:17 +01:00
|
|
|
const skipLog =
|
|
|
|
errorMessage.startsWith('Failed to download') ||
|
|
|
|
errorMessage.endsWith('Uploading the same file from multiple tabs or windows is not allowed.');
|
2019-07-23 22:13:06 +02:00
|
|
|
|
2022-01-06 08:26:03 +01:00
|
|
|
if (error.cause) {
|
|
|
|
try {
|
|
|
|
errorMessage += ' => ' + (JSON.stringify(error.cause, null, '\t') || '');
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e); // eslint-disable-line no-console
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 02:30:17 +01:00
|
|
|
if (process.env.NODE_ENV === 'production' && !skipLog) {
|
2022-01-06 08:26:03 +01:00
|
|
|
Lbryio.call('event', 'desktop_error', { error_message: errorMessage });
|
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
|
|
|
|
2022-01-06 08:26:03 +01:00
|
|
|
const errorObj = typeof error === 'string' ? { message: error, cause: undefined } : 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'),
|
2022-01-06 08:26:03 +01:00
|
|
|
cause: 'skip',
|
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)) {
|
2018-04-18 06:03:01 +02:00
|
|
|
const label = errorKeyLabels[key];
|
2022-01-06 08:26:03 +01:00
|
|
|
if (label !== 'skip') {
|
|
|
|
const val = typeof errorObj[key] === 'string' ? errorObj[key] : JSON.stringify(errorObj[key]);
|
|
|
|
errorInfoList.push(
|
|
|
|
<li key={key}>
|
|
|
|
<strong>{label}</strong>: {val}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
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;
|