Skip to content

Commit

Permalink
feat: timeout in config
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed May 21, 2023
1 parent cc5115a commit 3bc3ba3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class NeisRequest {
private readonly type: 'json' | 'xml'
private readonly pIndex: number
private readonly pSize: number
private readonly timeout: number

constructor(
config: NeisConfig & Required<Pick<NeisConfig, 'type' | 'pIndex' | 'pSize'>>
Expand All @@ -54,6 +55,8 @@ export class NeisRequest {
this.pIndex = config.pIndex
this.pSize = config.pSize

this.timeout = config.timeout ?? 5000

this.logger = config.logger?.getSubLogger({ name: 'HTTP' })

if (!this.key) {
Expand Down Expand Up @@ -126,7 +129,7 @@ export class NeisRequest {
}

private async get<T>(endpoint: string, params: Params) {
return this.request<T>('GET', endpoint, 5000, params)
return this.request<T>('GET', endpoint, this.timeout, params)
}

private async request<T>(
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { Logger } from 'tslog'
export interface NeisConfig extends DefaultParam {
/** tslog Logger */
readonly logger?: Logger<unknown>
/** Timeout in milliseconds */
readonly timeout?: number
}

interface DefaultParam {
Expand Down

0 comments on commit 3bc3ba3

Please sign in to comment.