refactor
This commit is contained in:
parent
6b19ac3e3d
commit
014ef7d35e
1 changed files with 8 additions and 10 deletions
|
|
@ -249,13 +249,16 @@ export function useConnection({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAuthError = async (error: unknown) => {
|
const is401Error = (error: unknown): boolean => {
|
||||||
const is401Error =
|
return (
|
||||||
(error instanceof SseError && error.code === 401) ||
|
(error instanceof SseError && error.code === 401) ||
|
||||||
(error instanceof Error && error.message.includes("401")) ||
|
(error instanceof Error && error.message.includes("401")) ||
|
||||||
(error instanceof Error && error.message.includes("Unauthorized"));
|
(error instanceof Error && error.message.includes("Unauthorized"))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if (is401Error) {
|
const handleAuthError = async (error: unknown) => {
|
||||||
|
if (is401Error(error)) {
|
||||||
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
|
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
|
||||||
|
|
||||||
const result = await auth(serverAuthProvider, { serverUrl: sseUrl });
|
const result = await auth(serverAuthProvider, { serverUrl: sseUrl });
|
||||||
|
|
@ -432,12 +435,7 @@ export function useConnection({
|
||||||
if (shouldRetry) {
|
if (shouldRetry) {
|
||||||
return connect(undefined, retryCount + 1);
|
return connect(undefined, retryCount + 1);
|
||||||
}
|
}
|
||||||
const is401Error =
|
if (is401Error(error)) {
|
||||||
(error instanceof SseError && error.code === 401) ||
|
|
||||||
(error instanceof Error && error.message.includes("401")) ||
|
|
||||||
(error instanceof Error && error.message.includes("Unauthorized"));
|
|
||||||
|
|
||||||
if (is401Error) {
|
|
||||||
// Don't set error state if we're about to redirect for auth
|
// Don't set error state if we're about to redirect for auth
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue