Skip to content

Commit d586f5f

Browse files
committed
enable/disable api instance
1 parent 1772c84 commit d586f5f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/plexus-api/src/api.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class ApiInstance {
4141
| Record<string, any>
4242
| Promise<Record<string, any>> = () => ({})
4343

44-
private waiting = false
44+
private disabled = false
4545
// "<method>:<path>": [() => void, ...]
4646
private waitingQueues: Map<string, (() => Promise<unknown>)[]> = new Map()
4747
constructor(
@@ -219,6 +219,7 @@ export class ApiInstance {
219219
body?: RequestInit['body']
220220
}
221221
) {
222+
if (this.disabled) return ApiInstance.createEmptyRes<ResponseDataType>(0)
222223
// this.addToQueue(`${this.genKey('GET', path)}`, () => {})
223224
const res = await this.send<ResponseDataType>(path, options)
224225
const headers = await this.headerGetter()
@@ -458,7 +459,7 @@ export class ApiInstance {
458459
.replace(' ', '-')
459460
] = value
460461
})
461-
this.waiting = false
462+
this.disabled = false
462463
Object.entries(headers || {}).map(([key, value]) => {
463464
// uppercase the dash separated tokens
464465
formattedHeaders[
@@ -518,6 +519,9 @@ export class ApiInstance {
518519
headers: Record<string, string>
519520
} & RequestInit
520521
}
522+
enabled(status: boolean = true) {
523+
this.disabled = !status
524+
}
521525
private static createEmptyRes<ResponseDataType = any>(status: number = 408) {
522526
return {
523527
status,

0 commit comments

Comments
 (0)