feat: character list error handling
This commit is contained in:
+62
-26
@@ -106,35 +106,71 @@ export function card(app: App) {
|
||||
)
|
||||
.get(
|
||||
"/genshin/:uid",
|
||||
async ({ params: { uid }, query: { debug, lang }, log }) => {
|
||||
// #region Character List
|
||||
const [[avatarStore, locs, pfps, namecards], data] =
|
||||
await Promise.all([
|
||||
deduper.acquire("stores", () =>
|
||||
batchStore("avatars", "locs", "pfps", "namecards").finally(
|
||||
() => log`Stores loaded`,
|
||||
async ({
|
||||
params: { uid },
|
||||
query: { debug, lang, error: errorType },
|
||||
log,
|
||||
}) => {
|
||||
const error =
|
||||
errorType === "card"
|
||||
? (_: number, message: string) => ErrorPage(message)
|
||||
: status;
|
||||
const errorLoc = cardErrorLocs[lang === "th" ? "th" : "en"];
|
||||
try {
|
||||
// #region Character List
|
||||
const [[avatarStore, locs, pfps, namecards], data] =
|
||||
await Promise.all([
|
||||
deduper.acquire("stores", () =>
|
||||
batchStore("avatars", "locs", "pfps", "namecards").finally(
|
||||
() => log`Stores loaded`,
|
||||
),
|
||||
),
|
||||
),
|
||||
feature("API") || uid !== "775956514"
|
||||
? deduper.acquire(`enka-${uid}`, () =>
|
||||
fetchEnka(uid, true).finally(() => log`Enka data loaded`),
|
||||
)
|
||||
: mockData,
|
||||
]);
|
||||
feature("API") || uid !== "775956514"
|
||||
? deduper.acquire(`enka-${uid}`, () =>
|
||||
fetchEnka(uid, true).finally(
|
||||
() => log`Enka data loaded`,
|
||||
),
|
||||
)
|
||||
: mockData,
|
||||
]);
|
||||
|
||||
if (debug) return { data };
|
||||
if (typeof data.playerInfo.showAvatarInfoList === "undefined")
|
||||
return error(400, errorLoc.private);
|
||||
|
||||
return ListPage(
|
||||
data,
|
||||
pfps[
|
||||
`${data.playerInfo.profilePicture.id ?? 1}`
|
||||
].IconPath.replace("_Circle", ""),
|
||||
namecards[`${data.playerInfo.nameCardId ?? 210001}`].Icon,
|
||||
namecards,
|
||||
avatarStore,
|
||||
locs[lang ?? "en"],
|
||||
log,
|
||||
);
|
||||
if (debug) return { data };
|
||||
|
||||
return ListPage(
|
||||
data,
|
||||
pfps[
|
||||
`${data.playerInfo.profilePicture.id ?? 1}`
|
||||
].IconPath.replace("_Circle", ""),
|
||||
namecards[`${data.playerInfo.nameCardId ?? 210001}`].Icon,
|
||||
namecards,
|
||||
avatarStore,
|
||||
locs[lang ?? "en"],
|
||||
log,
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof InvalidFormatError)
|
||||
return error(400, errorLoc.uidFormat);
|
||||
else if (err instanceof NotFoundError)
|
||||
return error(404, errorLoc.notFound);
|
||||
else if (err instanceof MaintenanceError)
|
||||
return error(424, errorLoc.maintenance);
|
||||
else if (err instanceof RatelimitError)
|
||||
return error(429, errorLoc.ratelimit);
|
||||
else if (err instanceof InternalError)
|
||||
return status(502, errorLoc.internal);
|
||||
console.error(err);
|
||||
try {
|
||||
return error(
|
||||
500,
|
||||
`Internal Error:\n${(err as { message: string })?.message || inspect(err)}` as "",
|
||||
);
|
||||
} catch {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
params: t.Object({
|
||||
|
||||
Reference in New Issue
Block a user