feat: specify timeout for api requests
ci/woodpecker/push/test Pipeline was successful
Details
ci/woodpecker/push/test Pipeline was successful
Details
This commit is contained in:
parent
0d034710b5
commit
0fbea77850
|
@ -4,7 +4,7 @@
|
|||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prepare": "husky install",
|
||||
"generate-client": "openapi --input src/lib/twhelp/openapi3.json --output src/lib/twhelp --name TWHelpClient --useOptions --client axios",
|
||||
"generate-client": "openapi --input src/lib/twhelp/openapi3.json --output src/lib/twhelp/generated --name TWHelpClient --useOptions --client axios",
|
||||
"build": "rm -rf dist && yarn generate-client && parcel build ./src/*.user.ts ./src/*.quickbar.ts",
|
||||
"postbuild": "PUBLIC_URL=https://scripts.twhelp.app node postbuild.js",
|
||||
"lint": "eslint src/**/*.ts"
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
Ennoblement,
|
||||
UnitInfo,
|
||||
ServerConfig,
|
||||
AxiosHttpRequestWithTimeout,
|
||||
} from './lib/twhelp';
|
||||
|
||||
declare global {
|
||||
|
@ -59,9 +60,12 @@ class TWHelpConnector {
|
|||
private readonly version: string,
|
||||
private readonly server: string
|
||||
) {
|
||||
this.client = new TWHelpClient({
|
||||
BASE: baseUrl,
|
||||
});
|
||||
this.client = new TWHelpClient(
|
||||
{
|
||||
BASE: baseUrl,
|
||||
},
|
||||
AxiosHttpRequestWithTimeout
|
||||
);
|
||||
}
|
||||
|
||||
serverConfig() {
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
import { InADayClient } from './lib/tw';
|
||||
import { createTranslationFunc } from './utils';
|
||||
import { buildURL } from './lib/twstats';
|
||||
import { TWHelpClient, PlayerSnapshot, Player } from './lib/twhelp';
|
||||
import {
|
||||
TWHelpClient,
|
||||
PlayerSnapshot,
|
||||
Player,
|
||||
AxiosHttpRequestWithTimeout,
|
||||
} from './lib/twhelp';
|
||||
import { DialogTable } from './common/dialog-table';
|
||||
import { Cache } from './lib/cache';
|
||||
|
||||
|
@ -68,9 +73,12 @@ class TWHelpConnector {
|
|||
private readonly server: string,
|
||||
private readonly id: number
|
||||
) {
|
||||
this.client = new TWHelpClient({
|
||||
BASE: baseUrl,
|
||||
});
|
||||
this.client = new TWHelpClient(
|
||||
{
|
||||
BASE: baseUrl,
|
||||
},
|
||||
AxiosHttpRequestWithTimeout
|
||||
);
|
||||
}
|
||||
|
||||
async player() {
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { Player, Tribe, TribeSnapshot, TWHelpClient } from './lib/twhelp';
|
||||
import {
|
||||
AxiosHttpRequestWithTimeout,
|
||||
Player,
|
||||
Tribe,
|
||||
TribeSnapshot,
|
||||
TWHelpClient,
|
||||
} from './lib/twhelp';
|
||||
import { createTranslationFunc } from './utils';
|
||||
import { buildURL } from './lib/twstats';
|
||||
import { DialogTable } from './common/dialog-table';
|
||||
|
@ -52,9 +58,12 @@ class TWHelpConnector {
|
|||
private readonly server: string,
|
||||
private readonly id: number
|
||||
) {
|
||||
this.client = new TWHelpClient({
|
||||
BASE: baseUrl,
|
||||
});
|
||||
this.client = new TWHelpClient(
|
||||
{
|
||||
BASE: baseUrl,
|
||||
},
|
||||
AxiosHttpRequestWithTimeout
|
||||
);
|
||||
}
|
||||
|
||||
async tribe() {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import { createTranslationFunc } from './utils';
|
||||
import { calcLoyalty } from './lib/tw';
|
||||
import { Cache } from './lib/cache';
|
||||
import { TWHelpClient, Ennoblement, ServerConfig } from './lib/twhelp';
|
||||
import {
|
||||
TWHelpClient,
|
||||
Ennoblement,
|
||||
ServerConfig,
|
||||
AxiosHttpRequestWithTimeout,
|
||||
} from './lib/twhelp';
|
||||
import { DialogTable } from './common/dialog-table';
|
||||
|
||||
const t = createTranslationFunc({
|
||||
|
@ -34,7 +39,12 @@ class TWHelpConnector {
|
|||
private readonly server: string,
|
||||
private readonly id: number
|
||||
) {
|
||||
this.client = new TWHelpClient({ BASE: baseUrl });
|
||||
this.client = new TWHelpClient(
|
||||
{
|
||||
BASE: baseUrl,
|
||||
},
|
||||
AxiosHttpRequestWithTimeout
|
||||
);
|
||||
}
|
||||
|
||||
serverConfig() {
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
*
|
||||
!.gitignore
|
||||
!openapi3.json
|
||||
generated
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
export * from './generated';
|
||||
export * from './timeout';
|
|
@ -0,0 +1,20 @@
|
|||
import axios from 'axios';
|
||||
import { request as __request } from './generated/core/request';
|
||||
import { CancelablePromise } from './generated/core/CancelablePromise';
|
||||
import { BaseHttpRequest } from './generated/core/BaseHttpRequest';
|
||||
import { ApiRequestOptions } from './generated/core/ApiRequestOptions';
|
||||
import type { OpenAPIConfig } from './generated/core/OpenAPI';
|
||||
|
||||
export class AxiosHttpRequestWithTimeout extends BaseHttpRequest {
|
||||
axiosInstance = axios.create({
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
constructor(config: OpenAPIConfig) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
public override request<T>(options: ApiRequestOptions): CancelablePromise<T> {
|
||||
return __request(this.config, options, this.axiosInstance);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue