|
1 | 1 | import { classifyError, parseRetryAfter } from '../errors'; |
2 | 2 |
|
3 | 3 | describe('classifyError', () => { |
| 4 | + describe('SDD-default config (statusCodeOverrides per spec)', () => { |
| 5 | + const sddConfig = { |
| 6 | + default4xxBehavior: 'drop' as const, |
| 7 | + default5xxBehavior: 'retry' as const, |
| 8 | + statusCodeOverrides: { |
| 9 | + '408': 'retry' as const, |
| 10 | + '410': 'retry' as const, |
| 11 | + '429': 'retry' as const, |
| 12 | + '460': 'retry' as const, |
| 13 | + '501': 'drop' as const, |
| 14 | + '505': 'drop' as const, |
| 15 | + }, |
| 16 | + rateLimitEnabled: true, |
| 17 | + }; |
| 18 | + |
| 19 | + it('retries 408 (Request Timeout)', () => { |
| 20 | + const result = classifyError(408, sddConfig); |
| 21 | + expect(result.isRetryable).toBe(true); |
| 22 | + expect(result.errorType).toBe('transient'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('retries 410 (Gone)', () => { |
| 26 | + const result = classifyError(410, sddConfig); |
| 27 | + expect(result.isRetryable).toBe(true); |
| 28 | + expect(result.errorType).toBe('transient'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('retries 460 (Client timeout)', () => { |
| 32 | + const result = classifyError(460, sddConfig); |
| 33 | + expect(result.isRetryable).toBe(true); |
| 34 | + expect(result.errorType).toBe('transient'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('rate-limits 429 (Too Many Requests)', () => { |
| 38 | + const result = classifyError(429, sddConfig); |
| 39 | + expect(result.isRetryable).toBe(true); |
| 40 | + expect(result.errorType).toBe('rate_limit'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('drops 400 (Bad Request)', () => { |
| 44 | + const result = classifyError(400, sddConfig); |
| 45 | + expect(result.isRetryable).toBe(false); |
| 46 | + expect(result.errorType).toBe('permanent'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('drops 401 (Unauthorized)', () => { |
| 50 | + const result = classifyError(401, sddConfig); |
| 51 | + expect(result.isRetryable).toBe(false); |
| 52 | + expect(result.errorType).toBe('permanent'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('drops 413 (Payload Too Large)', () => { |
| 56 | + const result = classifyError(413, sddConfig); |
| 57 | + expect(result.isRetryable).toBe(false); |
| 58 | + expect(result.errorType).toBe('permanent'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('drops 501 (Not Implemented)', () => { |
| 62 | + const result = classifyError(501, sddConfig); |
| 63 | + expect(result.isRetryable).toBe(false); |
| 64 | + expect(result.errorType).toBe('permanent'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('drops 505 (HTTP Version Not Supported)', () => { |
| 68 | + const result = classifyError(505, sddConfig); |
| 69 | + expect(result.isRetryable).toBe(false); |
| 70 | + expect(result.errorType).toBe('permanent'); |
| 71 | + }); |
| 72 | + |
| 73 | + it('retries 500 (Internal Server Error)', () => { |
| 74 | + const result = classifyError(500, sddConfig); |
| 75 | + expect(result.isRetryable).toBe(true); |
| 76 | + expect(result.errorType).toBe('transient'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('retries 502 (Bad Gateway)', () => { |
| 80 | + const result = classifyError(502, sddConfig); |
| 81 | + expect(result.isRetryable).toBe(true); |
| 82 | + expect(result.errorType).toBe('transient'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('retries 503 (Service Unavailable)', () => { |
| 86 | + const result = classifyError(503, sddConfig); |
| 87 | + expect(result.isRetryable).toBe(true); |
| 88 | + expect(result.errorType).toBe('transient'); |
| 89 | + }); |
| 90 | + |
| 91 | + it('retries 504 (Gateway Timeout)', () => { |
| 92 | + const result = classifyError(504, sddConfig); |
| 93 | + expect(result.isRetryable).toBe(true); |
| 94 | + expect(result.errorType).toBe('transient'); |
| 95 | + }); |
| 96 | + |
| 97 | + it('retries 508 (Loop Detected)', () => { |
| 98 | + const result = classifyError(508, sddConfig); |
| 99 | + expect(result.isRetryable).toBe(true); |
| 100 | + expect(result.errorType).toBe('transient'); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
4 | 104 | describe('statusCodeOverrides precedence', () => { |
5 | 105 | it('uses override for specific status code', () => { |
6 | 106 | const config = { |
|
0 commit comments