Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download web_app/src/utils/apiErrorMessage.test.ts from CommunityOne/open-navigator: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/CommunityOne/open-navigator/resolve/main/web_app/src/utils/apiErrorMessage.test.ts
- Command line
-
hf download hf://spaces/CommunityOne/open-navigator/web_app/src/utils/apiErrorMessage.test.ts
-
curl -L -o apiErrorMessage.test.ts https://huggingface.co/spaces/CommunityOne/open-navigator/resolve/main/web_app/src/utils/apiErrorMessage.test.ts
1.4 kB
| import { describe, expect, it } from 'vitest' | |
| import { ApiError, apiErrorMessage } from './apiErrorMessage' | |
| describe('apiErrorMessage (#888)', () => { | |
| it("reads FastAPI's detail", () => { | |
| expect(apiErrorMessage({ detail: 'No Lighthouse audit found for this URL' }, 404)).toBe( | |
| 'No Lighthouse audit found for this URL', | |
| ) | |
| }) | |
| it("reads this API's message when there is no detail", () => { | |
| const body = { error: 'Not Found', message: 'No Lighthouse audit found for this URL (run the scan).', path: '/api/x' } | |
| expect(apiErrorMessage(body, 404)).toBe('No Lighthouse audit found for this URL (run the scan).') | |
| }) | |
| it('joins validation messages', () => { | |
| expect(apiErrorMessage({ detail: [{ msg: 'Field required' }, { msg: 'Too short' }] }, 422)).toBe( | |
| 'Field required; Too short', | |
| ) | |
| }) | |
| it('falls back to the status code only when the body says nothing', () => { | |
| expect(apiErrorMessage(null, 404)).toBe('HTTP 404') | |
| expect(apiErrorMessage({}, 500)).toBe('HTTP 500') | |
| expect(apiErrorMessage({ detail: ' ' }, 502)).toBe('HTTP 502') | |
| expect(apiErrorMessage({ error: 'Bad Gateway' }, 502)).toBe('Bad Gateway') | |
| }) | |
| it('keeps the status on the error', () => { | |
| const e = new ApiError('nothing stored', 404) | |
| expect(e.status).toBe(404) | |
| expect(e.message).toBe('nothing stored') | |
| expect(e instanceof Error).toBe(true) | |
| }) | |
| }) | |