fix(api): propagate model server errors instead of silently masking with untouched image
This commit is contained in:
@@ -206,17 +206,20 @@ export async function executeBackendTryIt(
|
|||||||
// Validate if the response is actually an image or a JSON error
|
// Validate if the response is actually an image or a JSON error
|
||||||
const sig = checkFileSignature(resultBuffer);
|
const sig = checkFileSignature(resultBuffer);
|
||||||
if (!sig.valid) {
|
if (!sig.valid) {
|
||||||
try {
|
|
||||||
const textPayload = resultBuffer.toString('utf8');
|
const textPayload = resultBuffer.toString('utf8');
|
||||||
if (textPayload.startsWith('{') || textPayload.startsWith('[')) {
|
if (textPayload.startsWith('{') || textPayload.startsWith('[')) {
|
||||||
|
try {
|
||||||
const jsonResp = JSON.parse(textPayload);
|
const jsonResp = JSON.parse(textPayload);
|
||||||
console.warn(`[Backend API] Non-image payload from ${targetUrl}:`, jsonResp);
|
console.warn(`[Backend API] Non-image payload from ${targetUrl}:`, jsonResp);
|
||||||
if (jsonResp.error || jsonResp.message || jsonResp.status === false || jsonResp.status === 'error') {
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user