Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/client/test/client/sse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ describe('SSEClientTransport', () => {
expect(error).toBeInstanceOf(SdkHttpError);
expect((error as SdkHttpError).code).toBe(SdkErrorCode.ClientHttpAuthentication);
expect((error as SdkHttpError).status).toBe(401);
expect((error as SdkHttpError).statusText).toBe('Unauthorized');
expect(authProvider.onUnauthorized).toHaveBeenCalledTimes(1);
expect(postCount).toBe(2);
});
Expand Down
1 change: 1 addition & 0 deletions packages/client/test/client/streamableHttp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,7 @@ describe('StreamableHTTPClientTransport', () => {
expect(error).toBeInstanceOf(SdkHttpError);
expect((error as SdkHttpError).code).toBe(SdkErrorCode.ClientHttpAuthentication);
expect((error as SdkHttpError).status).toBe(401);
expect((error as SdkHttpError).statusText).toBe('Unauthorized');
expect(mockAuthProvider.saveTokens).toHaveBeenCalledWith({
access_token: 'new-access-token',
token_type: 'Bearer',
Expand Down
17 changes: 15 additions & 2 deletions packages/client/test/client/tokenProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,26 @@ describe('StreamableHTTPClientTransport with AuthProvider', () => {
vi.spyOn(globalThis, 'fetch');

(globalThis.fetch as Mock)
.mockResolvedValueOnce({ ok: false, status: 401, headers: new Headers(), text: async () => 'unauthorized' })
.mockResolvedValueOnce({ ok: false, status: 401, headers: new Headers(), text: async () => 'unauthorized' });
.mockResolvedValueOnce({
ok: false,
status: 401,
statusText: 'Unauthorized',
headers: new Headers(),
text: async () => 'unauthorized'
})
.mockResolvedValueOnce({
ok: false,
status: 401,
statusText: 'Unauthorized',
headers: new Headers(),
text: async () => 'unauthorized'
});

const error = await transport.send(message).catch(e => e);
expect(error).toBeInstanceOf(SdkHttpError);
expect((error as SdkHttpError).code).toBe(SdkErrorCode.ClientHttpAuthentication);
expect((error as SdkHttpError).status).toBe(401);
expect((error as SdkHttpError).statusText).toBe('Unauthorized');
expect(authProvider.onUnauthorized).toHaveBeenCalledTimes(1);
});

Expand Down
55 changes: 55 additions & 0 deletions packages/core/test/errors/sdkHttpError.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { describe, it, expect } from 'vitest';
import { SdkError, SdkErrorCode, SdkHttpError } from '../../src/index.js';

describe('SdkHttpError', () => {
it('exposes status and statusText via getters', () => {
const error = new SdkHttpError(SdkErrorCode.ClientHttpAuthentication, 'Unauthorized', {
status: 401,
statusText: 'Unauthorized'
});

expect(error.status).toBe(401);
expect(error.statusText).toBe('Unauthorized');
});

it('returns undefined for statusText when omitted', () => {
const error = new SdkHttpError(SdkErrorCode.ClientHttpAuthentication, 'auth failed', {
status: 401
});

expect(error.status).toBe(401);
expect(error.statusText).toBeUndefined();
});

it('is an instance of SdkError', () => {
const error = new SdkHttpError(SdkErrorCode.ClientHttpForbidden, 'Forbidden', {
status: 403,
statusText: 'Forbidden'
});

expect(error).toBeInstanceOf(SdkError);
expect(error).toBeInstanceOf(SdkHttpError);
});

it('preserves code and message from SdkError', () => {
const error = new SdkHttpError(SdkErrorCode.ClientHttpNotImplemented, 'Not Implemented', {
status: 501,
statusText: 'Not Implemented'
});

expect(error.code).toBe(SdkErrorCode.ClientHttpNotImplemented);
expect(error.message).toBe('Not Implemented');
expect(error.name).toBe('SdkHttpError');
});

it('exposes extra data fields alongside status', () => {
const error = new SdkHttpError(SdkErrorCode.ClientHttpAuthentication, 'auth failed', {
status: 401,
statusText: 'Unauthorized',
retryAfter: 30
});

expect(error.data.retryAfter).toBe(30);
expect(error.status).toBe(401);
});
});
Loading