mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-26 06:11:53 +01:00
Merge pull request #1122 from movie-web/fix/tmdb
Use vanilla AbortController for compatability
This commit is contained in:
commit
4712d8fc5d
@ -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 {
|
||||
@ -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), {
|
||||
@ -171,7 +177,7 @@ async function get<T>(url: string, params?: object): Promise<T> {
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
signal: AbortSignal.timeout(30000),
|
||||
signal: abortOnTimeout(30000),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user