Skip to content

Commit 75bb176

Browse files
committed
refactor: replace custom BackstageHttpError with AxiosError
1 parent 74f6cd9 commit 75bb176

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed

plugins/backstage-plugin-coder/src/api/errors.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

plugins/backstage-plugin-coder/src/components/CoderProvider/CoderAuthProvider.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
import { useApi } from '@backstage/core-plugin-api';
2020
import { type Theme, makeStyles } from '@material-ui/core';
2121
import { useId } from '../../hooks/hookPolyfills';
22-
import { BackstageHttpError } from '../../api/errors';
2322
import {
2423
CODER_QUERY_KEY_PREFIX,
2524
sharedAuthQueryKey,
@@ -329,11 +328,10 @@ function generateAuthState({
329328
};
330329
}
331330

332-
if (BackstageHttpError.isInstance(authValidityQuery.error)) {
331+
if (authValidityQuery.error instanceof AxiosError) {
333332
const deploymentLikelyUnavailable =
334333
authValidityQuery.error.status === 504 ||
335-
(authValidityQuery.error.status === 200 &&
336-
authValidityQuery.error.contentType !== 'application/json');
334+
authValidityQuery.error.status === 200;
337335

338336
if (deploymentLikelyUnavailable) {
339337
return {

plugins/backstage-plugin-coder/src/components/CoderProvider/CoderProvider.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
44
import { CoderAuthProvider } from './CoderAuthProvider';
55
import { CoderAppConfigProvider } from './CoderAppConfigProvider';
66
import { CoderErrorBoundary } from '../CoderErrorBoundary';
7-
import { BackstageHttpError } from '../../api/errors';
7+
import { AxiosError } from 'axios';
88

99
const MAX_FETCH_FAILURES = 3;
1010

@@ -15,19 +15,16 @@ export type CoderProviderProps = ComponentProps<typeof CoderAuthProvider> &
1515

1616
const shouldRetryRequest = (failureCount: number, error: unknown): boolean => {
1717
const isBelowThreshold = failureCount < MAX_FETCH_FAILURES;
18-
if (!BackstageHttpError.isInstance(error)) {
18+
if (!(error instanceof AxiosError)) {
1919
return isBelowThreshold;
2020
}
2121

22-
const isAuthenticationError = error.status === 401;
23-
const isLikelyProxyConfigurationError =
24-
error.status === 504 ||
25-
(error.status === 200 && error.contentType !== 'application/json');
22+
// We will get errors in the 500s range if the proxy isn't configured
23+
// properly, even if there are zero issues with the Coder deployment itself
24+
const isLikelyProxyConfigurationError = error.status === 504;
2625

2726
return (
28-
!isAuthenticationError &&
29-
!isLikelyProxyConfigurationError &&
30-
isBelowThreshold
27+
!isLikelyProxyConfigurationError && error.status !== 401 && isBelowThreshold
3128
);
3229
};
3330

0 commit comments

Comments
 (0)