refactor: Replace generic AnilistDurableObject fetch endpoint with dedicated methods and update their usage.
This commit is contained in:
@@ -6,25 +6,19 @@ export async function getUser(aniListToken: string): Promise<User> {
|
||||
const durableObjectId = env.ANILIST_DO.idFromName("GLOBAL");
|
||||
const stub = env.ANILIST_DO.get(durableObjectId);
|
||||
|
||||
const response = await stub.fetch("http://anilist-do/graphql", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operationName: "GetUser",
|
||||
variables: { token: aniListToken },
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 401) {
|
||||
let data;
|
||||
try {
|
||||
data = await stub.getUser(aniListToken);
|
||||
} catch (e: any) {
|
||||
if (e.message.includes("401")) {
|
||||
return null;
|
||||
}
|
||||
throw new Error(`Failed to fetch user: ${response.statusText}`);
|
||||
throw e;
|
||||
}
|
||||
|
||||
const data = (await response.json()) as any;
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...data,
|
||||
|
||||
Reference in New Issue
Block a user