mirror of
https://github.com/ansible/awx.git
synced 2026-02-25 23:16:01 -03:30
add redirect to login on 401
This commit is contained in:
@@ -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,22 +33,31 @@ 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 (
|
||||||
<EmptyState>
|
<Fragment>
|
||||||
<EmptyStateIcon icon={ExclamationTriangleIcon} />
|
{is401 ? (
|
||||||
<Title size="lg">
|
<Redirect to="/login" />
|
||||||
{is404 ? i18n._(t`Not Found`) : i18n._(t`Something went wrong...`)}
|
) : (
|
||||||
</Title>
|
<EmptyState>
|
||||||
<EmptyStateBody>
|
<EmptyStateIcon icon={ExclamationTriangleIcon} />
|
||||||
{is404
|
<Title size="lg">
|
||||||
? i18n._(t`The page you requested could not be found.`)
|
{is404 ? i18n._(t`Not Found`) : i18n._(t`Something went wrong...`)}
|
||||||
: i18n._(
|
</Title>
|
||||||
t`There was an error loading this content. Please reload the page.`
|
<EmptyStateBody>
|
||||||
)}{' '}
|
{is404
|
||||||
{children || <Link to="/home">{i18n._(t`Back to Dashboard.`)}</Link>}
|
? i18n._(t`The page you requested could not be found.`)
|
||||||
</EmptyStateBody>
|
: i18n._(
|
||||||
{error && <ErrorDetail error={error} />}
|
t`There was an error loading this content. Please reload the page.`
|
||||||
</EmptyState>
|
)}{' '}
|
||||||
|
{children || (
|
||||||
|
<Link to="/home">{i18n._(t`Back to Dashboard.`)}</Link>
|
||||||
|
)}
|
||||||
|
</EmptyStateBody>
|
||||||
|
{error && <ErrorDetail error={error} />}
|
||||||
|
</EmptyState>
|
||||||
|
)}
|
||||||
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ContentError.propTypes = {
|
ContentError.propTypes = {
|
||||||
|
|||||||
Reference in New Issue
Block a user