diff --git a/app/api/rmbg/route.ts b/app/api/rmbg/route.ts index 840c6b8c8..42ffe549c 100644 --- a/app/api/rmbg/route.ts +++ b/app/api/rmbg/route.ts @@ -309,6 +309,12 @@ async function processWithAosSegmentation( const state = Number(pollPayload.data.state); const imageUrl = pollPayload.data.image as string | undefined; + const stateDetail = String(pollPayload.data.state_detail || ""); + const errMessage = String(pollPayload.data.err_message || pollPayload.data.err_info || ""); + + if (pollCount === 0 || pollCount % 5 === 0) { + console.log(`[AOS RMBG] poll=${pollCount + 1} state=${state} detail=${stateDetail}`); + } if (state === 1 && imageUrl) { const imageResponse = await withTimeout( @@ -335,10 +341,11 @@ async function processWithAosSegmentation( }; } - if (state === 2 || state === 3 || state === -1) { + // AOS: state=2(Preparing) 属于处理中,不能当失败;只有负数状态视为失败 + if (state < 0) { return { success: false, - error: `AOS任务失败: ${pollPayload?.message || "状态异常"}`, + error: `AOS任务失败: ${errMessage || stateDetail || pollPayload?.message || "状态异常"}`, }; } }