Skip to content

Commit

Permalink
Use vanilla AbortController for compat
Browse files Browse the repository at this point in the history
  • Loading branch information
woldham-mgs committed Apr 15, 2024
1 parent 3c4d84d commit a9d80dd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/backend/metadata/tmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ const tmdbHeaders = {
Authorization: `Bearer ${apiKey}`,
};

function abortOnTimeout(timeout: number): AbortSignal {
const controller = new AbortController();
setTimeout(() => controller.abort(), timeout);
return controller.signal;
}

async function get<T>(url: string, params?: object): Promise<T> {
if (!apiKey) throw new Error("TMDB API key not set");
try {
Expand All @@ -162,7 +168,7 @@ async function get<T>(url: string, params?: object): Promise<T> {
params: {
...params,
},
signal: AbortSignal.timeout(5000),
signal: abortOnTimeout(5000),
});
} catch (err) {
return mwFetch<T>(encodeURI(url), {
Expand All @@ -171,7 +177,7 @@ async function get<T>(url: string, params?: object): Promise<T> {
params: {
...params,
},
signal: AbortSignal.timeout(30000),
signal: abortOnTimeout(30000),
});
}
}
Expand Down

0 comments on commit a9d80dd

Please sign in to comment.