fix: handle malformed ML service responses

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Asep Haryana Saputra
2026-05-22 20:00:01 +00:00
co-authored by Claude Opus 4.7
parent b81fecaa3f
commit e84be0d42f
2 changed files with 15 additions and 1 deletions
+6
View File
@@ -66,6 +66,12 @@ describe('classifyImage', () => {
await expect(classifyImage(makeImageFile())).rejects.toThrow('ML service returned 503: Model is not loaded');
});
test('throws when ML service returns malformed JSON', async () => {
mockFetch(async () => new Response('not-json', { status: 200, headers: { 'content-type': 'application/json' } }));
await expect(classifyImage(makeImageFile())).rejects.toThrow('Invalid ML service JSON response');
});
test('throws when ML service returns an unknown label', async () => {
mockFetch(async () => new Response(
JSON.stringify({