fix(core): support opting out of -503 resending
This commit is contained in:
parent
b6fac0785c
commit
aaa2875fe1
2 changed files with 15 additions and 2 deletions
|
@ -56,6 +56,6 @@ export async function getCallbackAnswer(
|
||||||
password,
|
password,
|
||||||
game: game,
|
game: game,
|
||||||
},
|
},
|
||||||
{ timeout },
|
{ timeout, throw503: true },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { tl } from '@mtcute/tl'
|
||||||
import { TlReaderMap, TlWriterMap } from '@mtcute/tl-runtime'
|
import { TlReaderMap, TlWriterMap } from '@mtcute/tl-runtime'
|
||||||
|
|
||||||
import { ITelegramStorage } from '../storage/index.js'
|
import { ITelegramStorage } from '../storage/index.js'
|
||||||
import { MtArgumentError, MtcuteError } from '../types/index.js'
|
import { MtArgumentError, MtcuteError, MtTimeoutError } from '../types/index.js'
|
||||||
import { ControllablePromise, createControllablePromise, ICryptoProvider, Logger, sleep } from '../utils/index.js'
|
import { ControllablePromise, createControllablePromise, ICryptoProvider, Logger, sleep } from '../utils/index.js'
|
||||||
import { assertTypeIs } from '../utils/type-assertions.js'
|
import { assertTypeIs } from '../utils/type-assertions.js'
|
||||||
import { ConfigManager } from './config-manager.js'
|
import { ConfigManager } from './config-manager.js'
|
||||||
|
@ -147,6 +147,14 @@ export interface RpcCallOptions {
|
||||||
* Abort signal for the call.
|
* Abort signal for the call.
|
||||||
*/
|
*/
|
||||||
abortSignal?: AbortSignal
|
abortSignal?: AbortSignal
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether we should not retry on -503 errors and throw {@link MtTimeoutError} immediately instead.
|
||||||
|
*
|
||||||
|
* Useful for methods like `messages.getBotCallbackAnswer` that reliably return
|
||||||
|
* -503 in case the upstream bot failed to respond.
|
||||||
|
*/
|
||||||
|
throw503?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -639,6 +647,7 @@ export class NetworkManager {
|
||||||
|
|
||||||
const floodSleepThreshold = params?.floodSleepThreshold ?? this.params.floodSleepThreshold
|
const floodSleepThreshold = params?.floodSleepThreshold ?? this.params.floodSleepThreshold
|
||||||
const maxRetryCount = params?.maxRetryCount ?? this.params.maxRetryCount
|
const maxRetryCount = params?.maxRetryCount ?? this.params.maxRetryCount
|
||||||
|
const throw503 = params?.throw503 ?? false
|
||||||
|
|
||||||
// do not send requests that are in flood wait
|
// do not send requests that are in flood wait
|
||||||
if (this._floodWaitedRequests.has(message._)) {
|
if (this._floodWaitedRequests.has(message._)) {
|
||||||
|
@ -691,6 +700,10 @@ export class NetworkManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(e.code in CLIENT_ERRORS)) {
|
if (!(e.code in CLIENT_ERRORS)) {
|
||||||
|
if (throw503 && e.code === -503) {
|
||||||
|
throw new MtTimeoutError()
|
||||||
|
}
|
||||||
|
|
||||||
this._log.warn('Telegram is having internal issues: %d %s, retrying', e.code, e.message)
|
this._log.warn('Telegram is having internal issues: %d %s, retrying', e.code, e.message)
|
||||||
|
|
||||||
if (e.text === 'WORKER_BUSY_TOO_LONG_RETRY') {
|
if (e.text === 'WORKER_BUSY_TOO_LONG_RETRY') {
|
||||||
|
|
Loading…
Reference in a new issue