import React from 'react'; import { translate } from 'react-i18next'; import { BackendError, ForbiddenError, UnauthorizedError } from './errors'; import Notification from './Notification'; import BackendErrorNotification from './BackendErrorNotification'; type Props = { t: (p: string) => string; error?: Error; }; class ErrorNotification extends React.Component { render() { const { t, error } = this.props; if (error) { if (error instanceof BackendError) { return ; } else if (error instanceof UnauthorizedError) { return ( {t('errorNotification.prefix')}:{' '} {t('errorNotification.timeout')}{' '} {t('errorNotification.loginLink')} ); } else if (error instanceof ForbiddenError) { return ( {t('errorNotification.prefix')}:{' '} {t('errorNotification.forbidden')} ); } else { return ( {t('errorNotification.prefix')}: {error.message} ); } } return null; } } export default translate('commons')(ErrorNotification);