add redirect to login on 401

This commit is contained in:
John Mitchell
2020-01-17 13:40:55 -05:00
parent cf34a81af7
commit 8d4d718f7d

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React, { Fragment } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { Link } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import { bool, instanceOf } from 'prop-types'; import { bool, instanceOf } from 'prop-types';
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { withI18n } from '@lingui/react'; import { withI18n } from '@lingui/react';
@@ -33,7 +33,12 @@ function ContentError({ error, children, isNotFound, i18n }) {
} }
const is404 = const is404 =
isNotFound || (error && error.response && error.response.status === 404); isNotFound || (error && error.response && error.response.status === 404);
const is401 = error && error.response && error.response.status === 401;
return ( return (
<Fragment>
{is401 ? (
<Redirect to="/login" />
) : (
<EmptyState> <EmptyState>
<EmptyStateIcon icon={ExclamationTriangleIcon} /> <EmptyStateIcon icon={ExclamationTriangleIcon} />
<Title size="lg"> <Title size="lg">
@@ -45,10 +50,14 @@ function ContentError({ error, children, isNotFound, i18n }) {
: i18n._( : i18n._(
t`There was an error loading this content. Please reload the page.` t`There was an error loading this content. Please reload the page.`
)}{' '} )}{' '}
{children || <Link to="/home">{i18n._(t`Back to Dashboard.`)}</Link>} {children || (
<Link to="/home">{i18n._(t`Back to Dashboard.`)}</Link>
)}
</EmptyStateBody> </EmptyStateBody>
{error && <ErrorDetail error={error} />} {error && <ErrorDetail error={error} />}
</EmptyState> </EmptyState>
)}
</Fragment>
); );
} }
ContentError.propTypes = { ContentError.propTypes = {