Skip to content

Commit b52bc34

Browse files
fix(core): use SdkError(NotConnected) in request() to match notification path
1 parent 3575410 commit b52bc34

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

packages/core/src/shared/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ export abstract class Protocol<ContextT extends BaseContext> {
811811
};
812812

813813
if (!this._transport) {
814-
earlyReject(new Error('Not connected'));
814+
earlyReject(new SdkError(SdkErrorCode.NotConnected, 'Not connected'));
815815
return;
816816
}
817817

packages/core/test/shared/customMethods.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@ describe('custom notification handlers', () => {
169169
});
170170

171171
describe('sendCustomRequest', () => {
172-
test('not connected -> rejects', async () => {
172+
test('not connected -> throws SdkError NotConnected', async () => {
173173
const proto = new TestProtocol();
174-
await expect(proto.sendCustomRequest('acme/x', {}, z.object({}))).rejects.toThrow(/Not connected/);
174+
await expect(proto.sendCustomRequest('acme/x', {}, z.object({}))).rejects.toSatisfy(
175+
(e: unknown) => e instanceof SdkError && e.code === SdkErrorCode.NotConnected
176+
);
175177
});
176178

177179
test('undefined params accepted', async () => {

0 commit comments

Comments
 (0)