summaryrefslogtreecommitdiff
path: root/packages/backend/test/unit/misc/is-retryable-error.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/test/unit/misc/is-retryable-error.ts')
-rw-r--r--packages/backend/test/unit/misc/is-retryable-error.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/packages/backend/test/unit/misc/is-retryable-error.ts b/packages/backend/test/unit/misc/is-retryable-error.ts
index 096bf64d4f..6d241066f7 100644
--- a/packages/backend/test/unit/misc/is-retryable-error.ts
+++ b/packages/backend/test/unit/misc/is-retryable-error.ts
@@ -8,6 +8,9 @@ import { AbortError } from 'node-fetch';
import { isRetryableError } from '@/misc/is-retryable-error.js';
import { StatusError } from '@/misc/status-error.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
+import { CaptchaError, captchaErrorCodes } from '@/core/CaptchaService.js';
+import { FastifyReplyError } from '@/misc/fastify-reply-error.js';
+import { ConflictError } from '@/server/SkRateLimiterService.js';
describe(isRetryableError, () => {
it('should return true for retryable StatusError', () => {
@@ -55,6 +58,78 @@ describe(isRetryableError, () => {
expect(result).toBeTruthy();
});
+ it('should return false for CaptchaError with verificationFailed', () => {
+ const error = new CaptchaError(captchaErrorCodes.verificationFailed, 'verificationFailed');
+ const result = isRetryableError(error);
+ expect(result).toBeFalsy();
+ });
+
+ it('should return false for CaptchaError with invalidProvider', () => {
+ const error = new CaptchaError(captchaErrorCodes.invalidProvider, 'invalidProvider');
+ const result = isRetryableError(error);
+ expect(result).toBeFalsy();
+ });
+
+ it('should return false for CaptchaError with invalidParameters', () => {
+ const error = new CaptchaError(captchaErrorCodes.invalidParameters, 'invalidParameters');
+ const result = isRetryableError(error);
+ expect(result).toBeFalsy();
+ });
+
+ it('should return true for CaptchaError with noResponseProvided', () => {
+ const error = new CaptchaError(captchaErrorCodes.noResponseProvided, 'noResponseProvided');
+ const result = isRetryableError(error);
+ expect(result).toBeTruthy();
+ });
+
+ it('should return true for CaptchaError with requestFailed', () => {
+ const error = new CaptchaError(captchaErrorCodes.requestFailed, 'requestFailed');
+ const result = isRetryableError(error);
+ expect(result).toBeTruthy();
+ });
+
+ it('should return true for CaptchaError with unknown', () => {
+ const error = new CaptchaError(captchaErrorCodes.unknown, 'unknown');
+ const result = isRetryableError(error);
+ expect(result).toBeTruthy();
+ });
+
+ it('should return true for CaptchaError with any other', () => {
+ const error = new CaptchaError(Symbol('temp'), 'unknown');
+ const result = isRetryableError(error);
+ expect(result).toBeTruthy();
+ });
+
+ it('should return false for FastifyReplyError', () => {
+ const error = new FastifyReplyError(400, 'test error');
+ const result = isRetryableError(error);
+ expect(result).toBeFalsy();
+ });
+
+ it('should return true for ConflictError', () => {
+ const error = new ConflictError('test error');
+ const result = isRetryableError(error);
+ expect(result).toBeTruthy();
+ });
+
+ it('should return true for AggregateError when all inners are retryable', () => {
+ const error = new AggregateError([
+ new ConflictError(),
+ new ConflictError(),
+ ]);
+ const result = isRetryableError(error);
+ expect(result).toBeTruthy();
+ });
+
+ it('should return true for AggregateError when any error is not retryable', () => {
+ const error = new AggregateError([
+ new ConflictError(),
+ new StatusError('test err', 400),
+ ]);
+ const result = isRetryableError(error);
+ expect(result).toBeFalsy();
+ });
+
const nonErrorInputs = [
[null, 'null'],
[undefined, 'undefined'],