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

This commit is contained in:
alina 🌸 2025-01-27 18:20:34 +03:00
parent dc87af3b40
commit d0b8366a5f
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

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()
}