Compare commits

...

2 commits

Author SHA1 Message Date
d0b8366a5f
feat(core): allow excluding internal errors from retrying
Some checks failed
Tests / test-deno (push) Successful in 1m44s
Tests / test-bun (push) Successful in 1m52s
Tests / test-node (node22) (push) Successful in 1m57s
Tests / test-node (node20) (push) Successful in 2m2s
Tests / test-node (node18) (push) Successful in 2m6s
Tests / test-web (chromium) (push) Successful in 2m4s
Tests / test-web (firefox) (push) Successful in 2m13s
Build and deploy typedoc / build (push) Successful in 5m58s
Tests / lint (push) Successful in 6m35s
Tests / e2e (push) Successful in 55s
Tests / e2e-deno (push) Failing after 1m8s
2025-01-27 18:20:34 +03:00
dc87af3b40
fix(core): export all default middlewares
me dum lol
2025-01-27 18:18:34 +03:00
2 changed files with 12 additions and 1 deletions

View file

@ -1,3 +1,5 @@
export * from './default.js'
export * from './flood-waiter.js'
export * from './internal-errors.js'
export * from './on-error.js'
export * from './on-method.js'

View file

@ -31,10 +31,17 @@ export interface InternalErrorsHandlerOptions {
* @default 1
*/
waitTime?: number
/**
* List of internal errors that should not be retried and should be thrown immediately.
*/
exceptErrors?: string[]
}
export function internalErrorsHandler(params: InternalErrorsHandlerOptions): RpcCallMiddleware {
const { maxRetries = Infinity, waitTime = 1 } = params
const { maxRetries = Infinity, waitTime = 1, exceptErrors } = params
const exceptErrorsSet = exceptErrors ? new Set(exceptErrors) : undefined
return async (ctx, next) => {
const numRetries = ctx.params?.maxRetryCount ?? maxRetries
@ -44,6 +51,8 @@ export function internalErrorsHandler(params: InternalErrorsHandlerOptions): Rpc
if (!isTlRpcError(res)) return res
if (!CLIENT_ERRORS.has(res.errorCode)) {
if (exceptErrorsSet?.has(res.errorMessage)) return res
if (ctx.params?.throw503 && res.errorCode === -503) {
throw new MtTimeoutError()
}