From ab9a4f21998fba52de3b23a40df93c0853fca9fe Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Wed, 11 Nov 2026 18:20:33 +0530 Subject: [PATCH] fix(api): propagate model server errors instead of silently masking with untouched image --- src/lib/api/requestBuilder.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/api/requestBuilder.ts b/src/lib/api/requestBuilder.ts index 73906b3..a7e78c6 100644 --- a/src/lib/api/requestBuilder.ts +++ b/src/lib/api/requestBuilder.ts @@ -206,17 +206,20 @@ export async function executeBackendTryIt( // Validate if the response is actually an image or a JSON error const sig = checkFileSignature(resultBuffer); if (!sig.valid) { - try { - const textPayload = resultBuffer.toString('utf8'); - if (textPayload.startsWith('{') || textPayload.startsWith('[')) { + const textPayload = resultBuffer.toString('utf8'); + if (textPayload.startsWith('{') || textPayload.startsWith('[')) { + try { const jsonResp = JSON.parse(textPayload); console.warn(`[Backend API] Non-image payload from ${targetUrl}:`, jsonResp); if (jsonResp.error || jsonResp.message || jsonResp.status === false || jsonResp.status === 'error') { - return await generateMockNeuralResult(imageBuffer, toolId, variantId); + const errMsg = jsonResp.error || jsonResp.message || 'Processing failed from model server'; + throw new Error(typeof errMsg === 'string' ? errMsg : JSON.stringify(errMsg)); + } + } catch (e: any) { + if (e.message && !e.message.includes('JSON at position')) { + throw e; } } - } catch { - // Fallback } }