forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-40-Lilly-Protocol-lily-sdk.ts
More file actions
42 lines (36 loc) · 1.32 KB
/
Copy pathgithub-40-Lilly-Protocol-lily-sdk.ts
File metadata and controls
42 lines (36 loc) · 1.32 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
// lily-sdk/src/errors/LilyTransportError.ts
export class LilyTransportError extends Error {
readonly cause?: Error;
constructor(message: string, options?: { cause?: Error }) {
super(message);
this.name = 'LilyTransportError';
if (options?.cause) {
Object.defineProperty(this, 'cause', {
value: options.cause,
enumerable: false,
writable: true,
configurable: true
});
}
// Ensure proper stack trace capture
if (Error.captureStackTrace) {
Error.captureStackTrace(this, LilyTransportError);
}
}
}
// lily-sdk/src/errors/__tests__/LilyTransportError.test.ts
import { LilyTransportError } from '../LilyTransportError';
describe('LilyTransportError', () => {
it('should propagate cause correctly', () => {
const originalError = new Error('original error');
const wrappedError = new LilyTransportError('transport failed', { cause: originalError });
expect(wrappedError.cause).toBe(originalError);
expect(wrappedError.message).toBe('transport failed');
expect(wrappedError.name).toBe('LilyTransportError');
});
it('should handle missing cause gracefully', () => {
const error = new LilyTransportError('no cause provided');
expect(error.cause).toBeUndefined();
expect(error.message).toBe('no cause provided');
});
});