MCPcopy Create free account
hub / github.com/pollinations/pollinations / upstreamErrorResponse

Function upstreamErrorResponse

apps/websim/worker.js:322–343  ·  view source on GitHub ↗
(upstream)

Source from the content-addressed store, hash-verified

320}
321
322async function upstreamErrorResponse(upstream) {
323 const upstreamStatus = upstream?.status || 502;
324 const status =
325 upstreamStatus >= 400 && upstreamStatus < 500 ? upstreamStatus : 502;
326 const detail = upstream ? await readResponsePreview(upstream, 4096) : "";
327
328 return new Response(
329 renderErrorPage(
330 `Upstream error ${upstreamStatus}`,
331 detail ||
332 "The Pollinations text API did not return generated HTML for this request.",
333 ),
334 {
335 status,
336 headers: {
337 "Content-Type": "text/html; charset=utf-8",
338 "Cache-Control": "no-store",
339 ...getCorsHeaders(),
340 },
341 },
342 );
343}
344
345async function readResponsePreview(response, maxChars) {
346 if (!response.body) return "";

Callers 1

generateHtmlFunction · 0.85

Calls 3

readResponsePreviewFunction · 0.85
renderErrorPageFunction · 0.85
getCorsHeadersFunction · 0.85

Tested by

no test coverage detected