Skip to content

Commit

Permalink
Merge pull request #2915 from Hyperkid123/account-on-hold-error-screen
Browse files Browse the repository at this point in the history
Catch on hold account error globally.
  • Loading branch information
Hyperkid123 authored Aug 13, 2024
2 parents d5f7cc7 + 59e67df commit fde3cd0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cypress/component/GatewayErrors.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { removeScalprum } from '@scalprum/core';
import type { AuthContextProps } from 'react-oidc-context';
import { ChromeUser } from '@redhat-cloud-services/types';
import { Provider as JotaiProvider, createStore, useAtomValue } from 'jotai';
import { AxiosError, AxiosResponse } from 'axios';

import qe from '../../src/utils/iqeEnablement';
import { COMPLIACE_ERROR_CODES } from '../../src/utils/responseInterceptors';
Expand All @@ -16,6 +17,7 @@ import { initializeVisibilityFunctions } from '../../src/utils/VisibilitySinglet
import GatewayErrorComponent from '../../src/components/ErrorComponents/GatewayErrorComponent';
import { activeModuleAtom } from '../../src/state/atoms/activeModuleAtom';
import { gatewayErrorAtom } from '../../src/state/atoms/gatewayErrorAtom';
import ErrorBoundary from '../../src/components/ErrorComponents/ErrorBoundary';

const testUser: ChromeUser = testUserJson as unknown as ChromeUser;

Expand Down Expand Up @@ -243,4 +245,46 @@ describe('Gateway errors', () => {
cy.contains(`Normal render`).should('not.exist');
cy.contains(`Component error handler`).should('exist');
});

describe('Global error boundary', () => {
const resp = {
errors: [
{
detail:
"Insights authorization failed - ERROR_EXPORT_CONTROL: Your account appears to be on Export Hold. Please review the information at the following link for more detail: <a href='https://access.redhat.com/articles/1340183'>https://access.redhat.com/articles/1340183</a>. (SS v3)",
meta: {
response_by: 'gateway',
},
status: 403,
},
],
};
const axiosResp: AxiosResponse<typeof resp> = {
config: {},
data: resp,
status: 403,
statusText: 'Forbidden',
headers: {},
};
const onHoldError = new AxiosError<typeof resp>('Insights authorization failed', 'resp', {}, null, axiosResp);

const ThrowComponent = () => {
throw onHoldError;
};
it('handles account on hold error', () => {
cy.on('uncaught:exception', () => {
// ignore exception, they are expected in this test case
return false;
});
cy.mount(
<IntlProvider locale="en">
<ErrorBoundary>
<ThrowComponent />
</ErrorBoundary>
</IntlProvider>
);

cy.contains('Your account appears to be on Export Hold').should('exist');
});
});
});
17 changes: 17 additions & 0 deletions src/components/ErrorComponents/AccountOnHoldError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { AxiosError } from 'axios';
import NotAuthorized from '@redhat-cloud-services/frontend-components/NotAuthorized';

const ON_HOLD_MARK = 'Insights authorization failed - ERROR_EXPORT_CONTROL:';

export const checkAccountOnHold = (error: any) => {
return error?.response?.data?.errors?.[0]?.detail.includes(ON_HOLD_MARK);
};

const AccountOnHoldError = ({ error }: { error: AxiosError<{ errors: { detail: string }[] }> }) => {
const data = error.response?.data.errors[0].detail;
const description = <div dangerouslySetInnerHTML={{ __html: data! }}></div>;
return <NotAuthorized description={description} serviceName="Hybrid Cloud Console" />;
};

export default AccountOnHoldError;
4 changes: 4 additions & 0 deletions src/components/ErrorComponents/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import ErrorComponent from './DefaultErrorComponent';
import AccountOnHoldError, { checkAccountOnHold } from './AccountOnHoldError';

type ErrorBoundaryState = {
hasError: boolean;
Expand Down Expand Up @@ -50,6 +51,9 @@ class ErrorBoundary extends React.Component<

render() {
if (this.state.hasError) {
if (checkAccountOnHold(this.state.error)) {
return <AccountOnHoldError error={this.state.error} />;
}
return <ErrorComponent error={this.state.error} errorInfo={this.state.errorInfo} signIn={this.props.singIn} />;
}

Expand Down

0 comments on commit fde3cd0

Please sign in to comment.