Skip to content

Commit

Permalink
refactor(content/keyAutoAdd): improve timeout handling (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Oct 10, 2024
1 parent ce60e14 commit c344e35
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/content/keyAutoAdd/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function waitForURL(
const abortSignal = AbortSignal.timeout(timeout);
abortSignal.addEventListener('abort', (e) => {
observer.disconnect();
reject(e);
reject(new TimeoutError(`Timeout waiting for URL`, { cause: e }));
});

let url = window.location.href;
Expand All @@ -43,11 +43,13 @@ export async function waitForURL(
return promise;
}

class TimeoutError extends Error {
name = 'TimeoutError';
constructor(message: string, { cause }: { cause: Event }) {
super(message, { cause });
}
}

export function isTimedOut(e: any) {
return (
e instanceof Event &&
e.type === 'abort' &&
e.currentTarget instanceof AbortSignal &&
e.currentTarget.reason?.name === 'TimeoutError'
);
return e instanceof TimeoutError;
}

0 comments on commit c344e35

Please sign in to comment.