Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMT-3923: Catch intermittent error from EDL #1329

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion static/src/js/components/ErrorBoundary/ErrorBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ class ErrorBoundary extends React.Component {
}

static getDerivedStateFromError(error) {
let errorMessage = error.message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a test that mocks this response

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in ErrorBoundary.test.js

// Check to see if it is a known intermittent error from EDL (MMT-3923)
if (error.graphQLErrors
&& (error.graphQLErrors[0]?.extensions?.code === 'INTERNAL_SERVER_ERROR')
&& error.graphQLErrors[0]?.path?.includes('acl')
&& error.graphQLErrors[0]?.path?.includes('groups')) {
errorMessage = 'Error retrieving groups. Please refresh'
}

return {
hasError: true,
error: error.message
error: errorMessage
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import React from 'react'
import { render, screen } from '@testing-library/react'

import ErrorBoundary from '../ErrorBoundary'
import ErrorBanner from '../../ErrorBanner/ErrorBanner'

vi.mock('../../ErrorBanner/ErrorBanner')

const setup = () => {
render(
Expand Down Expand Up @@ -37,7 +34,34 @@ describe('ErrorBoundary', () => {
</ErrorBoundary>
)

expect(ErrorBanner).toHaveBeenCalled(1)
expect(screen.getByText('Test for ErrorBoundary')).toBeInTheDocument()
})
})

describe('when there is an EDL timeout error', () => {
vi.spyOn(console, 'error').mockImplementation(() => {})
test('renders error banner asking user to refresh browser', async () => {
const ThrowError = () => {
const error = new Error('An unknown error occurred')
error.graphQLErrors = [
{
extensions: {
code: 'INTERNAL_SERVER_ERROR'
},
path: ['acl', 'groups']
}
]

throw error
}

render(
<ErrorBoundary>
<ThrowError />
</ErrorBoundary>
)

expect(screen.getByText('Error retrieving groups. Please refresh')).toBeInTheDocument()
})
})
})
Loading