Merge pull request #5695 from jlmitch5/redirectToLogin

add redirect to login on 401

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-01-17 23:31:38 +00:00 committed by GitHub
commit 77d1c711bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import React from 'react';
import React, { Fragment } from 'react';
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 { t } from '@lingui/macro';
import { withI18n } from '@lingui/react';
@ -33,22 +33,31 @@ function ContentError({ error, children, isNotFound, i18n }) {
}
const is404 =
isNotFound || (error && error.response && error.response.status === 404);
const is401 = error && error.response && error.response.status === 401;
return (
<EmptyState>
<EmptyStateIcon icon={ExclamationTriangleIcon} />
<Title size="lg">
{is404 ? i18n._(t`Not Found`) : i18n._(t`Something went wrong...`)}
</Title>
<EmptyStateBody>
{is404
? i18n._(t`The page you requested could not be found.`)
: i18n._(
t`There was an error loading this content. Please reload the page.`
)}{' '}
{children || <Link to="/home">{i18n._(t`Back to Dashboard.`)}</Link>}
</EmptyStateBody>
{error && <ErrorDetail error={error} />}
</EmptyState>
<Fragment>
{is401 ? (
<Redirect to="/login" />
) : (
<EmptyState>
<EmptyStateIcon icon={ExclamationTriangleIcon} />
<Title size="lg">
{is404 ? i18n._(t`Not Found`) : i18n._(t`Something went wrong...`)}
</Title>
<EmptyStateBody>
{is404
? i18n._(t`The page you requested could not be found.`)
: i18n._(
t`There was an error loading this content. Please reload the page.`
)}{' '}
{children || (
<Link to="/home">{i18n._(t`Back to Dashboard.`)}</Link>
)}
</EmptyStateBody>
{error && <ErrorDetail error={error} />}
</EmptyState>
)}
</Fragment>
);
}
ContentError.propTypes = {