Skip to content

Commit

Permalink
Merge pull request #1122 from movie-web/fix/tmdb
Browse files Browse the repository at this point in the history
Use vanilla AbortController for compatability
  • Loading branch information
binaryoverload authored Apr 15, 2024
2 parents 3c4d84d + a9d80dd commit 4712d8f
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 4712d8f

Please sign in to comment.