feat: detect stat.ink's API error (#41)

main
imspace 2022-11-29 18:50:34 +08:00 committed by GitHub
parent 98081f41a9
commit 2a0bc5ff56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import {
StatInkPostBody, StatInkPostBody,
StatInkPostResponse, StatInkPostResponse,
StatInkStage, StatInkStage,
StatInkUuidList,
StatInkWeapon, StatInkWeapon,
VsHistoryDetail, VsHistoryDetail,
VsInfo, VsInfo,
@ -66,12 +67,23 @@ class StatInkAPI {
async uuidList(type: Game["type"]): Promise<string[]> { async uuidList(type: Game["type"]): Promise<string[]> {
const fetch = this.env.newFetcher(); const fetch = this.env.newFetcher();
return await (await fetch.get({ const response = await fetch.get({
url: type === "VsInfo" url: type === "VsInfo"
? `${this.statInk}/api/v3/s3s/uuid-list` ? `${this.statInk}/api/v3/s3s/uuid-list`
: `${this.statInk}/api/v3/salmon/uuid-list`, : `${this.statInk}/api/v3/salmon/uuid-list`,
headers: this.requestHeaders(), headers: this.requestHeaders(),
})).json(); });
const uuidResult: StatInkUuidList = await response.json();
if (!Array.isArray(uuidResult)) {
throw new APIError({
response,
json: uuidResult,
message: uuidResult.message,
});
}
return uuidResult;
} }
async postBattle(body: StatInkPostBody) { async postBattle(body: StatInkPostBody) {

View File

@ -552,6 +552,13 @@ export enum BattleListType {
Coop, Coop,
} }
export type StatInkUuidList = {
status: number;
code: number;
name: string;
message: string;
} | string[];
export type StatInkAbility = { export type StatInkAbility = {
key: string; key: string;
name: Record<string, string>; name: Record<string, string>;