Skip to content

Commit 014ef7d

Browse files
committed
refactor
1 parent 6b19ac3 commit 014ef7d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,16 @@ export function useConnection({
249249
}
250250
};
251251

252-
const handleAuthError = async (error: unknown) => {
253-
const is401Error =
252+
const is401Error = (error: unknown): boolean => {
253+
return (
254254
(error instanceof SseError && error.code === 401) ||
255255
(error instanceof Error && error.message.includes("401")) ||
256-
(error instanceof Error && error.message.includes("Unauthorized"));
256+
(error instanceof Error && error.message.includes("Unauthorized"))
257+
);
258+
};
257259

258-
if (is401Error) {
260+
const handleAuthError = async (error: unknown) => {
261+
if (is401Error(error)) {
259262
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
260263

261264
const result = await auth(serverAuthProvider, { serverUrl: sseUrl });
@@ -432,12 +435,7 @@ export function useConnection({
432435
if (shouldRetry) {
433436
return connect(undefined, retryCount + 1);
434437
}
435-
const is401Error =
436-
(error instanceof SseError && error.code === 401) ||
437-
(error instanceof Error && error.message.includes("401")) ||
438-
(error instanceof Error && error.message.includes("Unauthorized"));
439-
440-
if (is401Error) {
438+
if (is401Error(error)) {
441439
// Don't set error state if we're about to redirect for auth
442440

443441
return;

0 commit comments

Comments
 (0)