forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror-mapping.test.ts
More file actions
42 lines (38 loc) · 1.33 KB
/
Copy patherror-mapping.test.ts
File metadata and controls
42 lines (38 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { describe, it, expect } from 'vitest';
import {
LilyApiError,
LilyAuthenticationError,
LilyTransportError,
LilySdkError,
isLilySdkError,
} from '../src/errors/sdk-error';
describe('Error mapping 4xx/5xx (issue #7)', () => {
it('LilyApiError is thrown for 4xx/5xx responses', () => {
const error = new LilyApiError('Server error', {
code: 'API_ERROR',
statusCode: 500,
});
expect(error).toBeInstanceOf(LilySdkError);
expect(error.statusCode).toBe(500);
expect(error.code).toBe('API_ERROR');
});
it('LilyAuthenticationError is thrown for 401/403', () => {
const error = new LilyAuthenticationError('Unauthorized', {
statusCode: 401,
});
expect(error).toBeInstanceOf(LilySdkError);
expect(error.statusCode).toBe(401);
});
it('LilyTransportError is thrown for network failures', () => {
const cause = new Error('ECONNREFUSED');
const error = new LilyTransportError('Connection failed', { cause });
expect(error).toBeInstanceOf(LilySdkError);
expect(error.cause).toBe(cause);
});
it('isLilySdkError type guard works', () => {
const apiError = new LilyApiError('fail', { code: 'ERR', statusCode: 500 });
const plainError = new Error('plain');
expect(isLilySdkError(apiError)).toBe(true);
expect(isLilySdkError(plainError)).toBe(false);
});
});