Something went wrong. Try again.
ATProto-based AI Assistant Chat interface.
Something went wrong. Try again.
123456789101112131415161718192021222324import { afterEach, describe, expect, it, vi } from 'vitest'import { ApiError, onUnauthorized, read } from '../src/api.ts'
afterEach(() => vi.unstubAllGlobals())
describe('read', () => { it('tells listeners when a request finds the session has ended', async () => { const listener = vi.fn() const stop = onUnauthorized(listener) const response = Promise.resolve(Response.json({ error: 'Unauthorized' }, { status: 401 })) await expect(read(response as never)).rejects.toBeInstanceOf(ApiError) expect(listener).toHaveBeenCalledOnce() stop() })
it('reports the status when an error body is not JSON', async () => { const response = Promise.resolve(new Response('<html>Bad gateway</html>', { status: 502 })) await expect(read(response as never)).rejects.toMatchObject({ status: 502, message: 'Request failed with 502', }) })})