{"record":{"id":"8914688b0602c16e","repo":"DayuanJiang/next-ai-draw-io","slug":"unexpected-response-format-contenttype","errorCode":null,"errorMessage":"Unexpected response format: ${contentType}","messagePattern":"Unexpected response format: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/validate-model/route.ts","lineNumber":324,"sourceCode":"                        },\n                    )\n\n                    if (!response.ok) {\n                        const errorText = await response.text()\n                        throw new Error(\n                            `ModelScope API error (${response.status}): ${errorText}`,\n                        )\n                    }\n\n                    const contentType =\n                        response.headers.get(\"content-type\") || \"\"\n                    const isValidStreamingResponse =\n                        response.status === 200 &&\n                        (contentType.includes(\"text/event-stream\") ||\n                            contentType.includes(\"application/json\"))\n\n                    if (!isValidStreamingResponse) {\n                        throw new Error(\n                            `Unexpected response format: ${contentType}`,\n                        )\n                    }\n\n                    const responseTime = Date.now() - startTime\n\n                    if (response.body) {\n                        response.body.cancel().catch(() => {\n                            /* Ignore cancellation errors */\n                        })\n                    }\n\n                    return NextResponse.json({\n                        valid: true,\n                        responseTime,\n                        note: \"ModelScope model validated (using streaming API)\",\n                    })\n                } catch (error) {","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/app/api/validate-model/route.ts#L306-L342","documentation":"After a successful ModelScope HTTP 200, the validate-model route requires the response content-type to be text/event-stream or application/json; anything else (HTML error page, empty content-type) triggers this error.","triggerScenarios":"ModelScope returns 200 with text/html (login/captcha page), text/plain, or an empty content-type instead of the expected SSE stream or JSON.","commonSituations":"Gateway/CDN intercepting the request and returning HTML, wrong endpoint URL that serves a web page, or ModelScope API contract changes.","solutions":["Log the full contentType and response body to see what was actually returned","Verify the request URL is the ModelScope inference API endpoint, not the website","Check for proxies/middleware that rewrite the response","If ModelScope changed its response format, update isValidStreamingResponse to accept it"],"exampleFix":"// before\nif (!isValidStreamingResponse) {\n  throw new Error(`Unexpected response format: ${contentType}`)\n}\n\n// after\nif (!isValidStreamingResponse) {\n  const body = await response.text().catch(() => '')\n  throw new Error(\n    `Unexpected response format: ${contentType}; body: ${body.slice(0, 200)}`,\n  )\n}","handlingStrategy":"validation","validationCode":"const ACCEPTED = ['text/event-stream', 'application/json']\nconst ct = (await fetch(url)).headers.get('content-type') || ''\nif (!ACCEPTED.some((t) => ct.includes(t))) {\n  // don't attempt to stream; surface a config error\n}","typeGuard":"const isStreamableContent = (ct: string): boolean =>\n  ct.includes('text/event-stream') || ct.includes('application/json')","tryCatchPattern":"try { /* consume stream */ } catch (e) {\n  if ((e as Error).message.startsWith('Unexpected response format')) {\n    logContentType(); checkEndpointUrl()\n  }\n}","preventionTips":["Verify the ModelScope endpoint URL returns SSE/JSON before wiring streaming","Log content-type plus body snippet for diagnosis","Watch for HTML responses from proxies/captchas"],"tags":["modelscope","content-type","http","validation"],"backgroundTag":"unexpected-content-type","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}