forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh-disc-40-Lilly-Protocol-lily-sdk.ts
More file actions
62 lines (50 loc) · 1.83 KB
/
Copy pathgh-disc-40-Lilly-Protocol-lily-sdk.ts
File metadata and controls
62 lines (50 loc) · 1.83 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// lily-transport-error.ts
export class LilyTransportError extends Error {
constructor(
message: string,
options?: { cause?: unknown; code?: string }
) {
super(message, { cause: options?.cause });
this.name = 'LilyTransportError';
// For Node.js <18.0.0 or older environments without native cause support
if (options?.cause && !(this as any).cause) {
(this as any).cause = options.cause;
}
if (options?.code) {
this.code = options.code;
}
// Maintain proper prototype chain
Object.setPrototypeOf(this, LilyTransportError.prototype);
}
code?: string;
}
// lily-transport-error.test.ts
import { LilyTransportError } from './lily-transport-error';
describe('LilyTransportError', () => {
test('should propagate cause correctly', () => {
const originalError = new Error('Original error');
const transportError = new LilyTransportError('Transport failed', {
cause: originalError,
code: 'NETWORK_ERROR'
});
expect(transportError.message).toBe('Transport failed');
expect(transportError.cause).toBe(originalError);
expect(transportError.code).toBe('NETWORK_ERROR');
});
test('should handle cause as non-Error object', () => {
const cause = { message: 'Custom cause', code: 500 };
const transportError = new LilyTransportError('Transport failed', {
cause
});
expect(transportError.cause).toBe(cause);
});
test('should work without cause', () => {
const transportError = new LilyTransportError('Transport failed');
expect(transportError.message).toBe('Transport failed');
expect(transportError.cause).toBeUndefined();
});
test('should maintain prototype chain', () => {
const transportError = new LilyTransportError('Test error');
expect(transportError).toBeInstanceOf(LilyTransportError);
});
});