chore(native-filters): Ensure consistent error handling (#24206)

Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com>
This commit is contained in:
John Bodley
2023-05-30 09:08:38 -07:00
committed by GitHub
parent 6e7b93eb48
commit 674da1b209
5 changed files with 75 additions and 31 deletions

View File

@@ -37,6 +37,7 @@ const StyledContent = styled.div`
display: flex;
flex-direction: column;
margin-left: ${({ theme }) => theme.gridUnit * 2}px;
overflow: hidden;
`;
const StyledTitle = styled.span`

View File

@@ -21,7 +21,8 @@ import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import ErrorMessageWithStackTrace from './ErrorMessageWithStackTrace';
import { ErrorLevel, ErrorSource } from './types';
import BasicErrorAlert from './BasicErrorAlert';
import { ErrorLevel, ErrorSource, ErrorTypeEnum } from './types';
jest.mock(
'src/components/Icons/Icon',
@@ -57,3 +58,21 @@ test('should render the link', () => {
expect(link).toHaveTextContent('(Request Access)');
expect(link).toHaveAttribute('href', mockedProps.link);
});
test('should render the fallback', () => {
const body = 'Blahblah';
render(
<ErrorMessageWithStackTrace
error={{
error_type: ErrorTypeEnum.FRONTEND_NETWORK_ERROR,
message: body,
extra: {},
level: 'error',
}}
fallback={<BasicErrorAlert title="Blah" body={body} level="error" />}
{...mockedProps}
/>,
{ useRedux: true },
);
expect(screen.getByText(body)).toBeInTheDocument();
});

View File

@@ -34,6 +34,7 @@ type Props = {
source?: ErrorSource;
description?: string;
errorMitigationFunction?: () => void;
fallback?: React.ReactNode;
};
export default function ErrorMessageWithStackTrace({
@@ -45,6 +46,7 @@ export default function ErrorMessageWithStackTrace({
stackTrace,
source,
description,
fallback,
}: Props) {
// Check if a custom error message component was registered for this message
if (error) {
@@ -62,6 +64,10 @@ export default function ErrorMessageWithStackTrace({
}
}
if (fallback) {
return <>{fallback}</>;
}
return (
<ErrorAlert
level="warning"