feat: detect stat.ink's API error (#41)
parent
98081f41a9
commit
2a0bc5ff56
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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>;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue