Skip to content

Commit 6f9f8d0

Browse files
author
Benibur
committed
feat(03-01): add DESTROYED to OBCErrorCode union and extend errors.test.ts
1 parent 3fbb996 commit 6f9f8d0

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

open-buro-client/src/errors.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,35 @@ describe('OBCError', () => {
1111
expect(e.name).toBe('OBCError');
1212
});
1313

14-
it('accepts all six error codes', () => {
14+
it('accepts all seven error codes', () => {
1515
const codes: OBCErrorCode[] = [
1616
'CAPABILITIES_FETCH_FAILED',
1717
'NO_MATCHING_CAPABILITY',
1818
'IFRAME_TIMEOUT',
1919
'WS_CONNECTION_FAILED',
2020
'INTENT_CANCELLED',
2121
'SAME_ORIGIN_CAPABILITY',
22+
'DESTROYED',
2223
];
2324
for (const code of codes) {
2425
const e = new OBCError(code, 'x');
2526
expect(e.code).toBe(code);
2627
}
28+
expect(codes.length).toBe(7);
29+
});
30+
31+
it('constructs with DESTROYED code', () => {
32+
const err = new OBCError('DESTROYED', 'OpenBuroClient has been destroyed');
33+
expect(err.code).toBe('DESTROYED');
34+
expect(err.message).toBe('OpenBuroClient has been destroyed');
35+
expect(err).toBeInstanceOf(OBCError);
36+
expect(err).toBeInstanceOf(Error);
37+
});
38+
39+
it('carries cause on DESTROYED errors', () => {
40+
const cause = new Error('underlying');
41+
const err = new OBCError('DESTROYED', 'x', cause);
42+
expect(err.cause).toBe(cause);
2743
});
2844

2945
it('preserves cause when provided', () => {

open-buro-client/src/errors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export type OBCErrorCode =
66
| 'IFRAME_TIMEOUT'
77
| 'WS_CONNECTION_FAILED'
88
| 'INTENT_CANCELLED'
9-
| 'SAME_ORIGIN_CAPABILITY';
9+
| 'SAME_ORIGIN_CAPABILITY'
10+
| 'DESTROYED';
1011

1112
export class OBCError extends Error {
1213
readonly code: OBCErrorCode;

0 commit comments

Comments
 (0)