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 } }