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

Function ensureUpstreamOk

shared/error.ts:68–84  ·  view source on GitHub ↗
(
    response: Response,
    requestUrl: string | URL,
)

Source from the content-addressed store, hash-verified

66}
67
68export async function ensureUpstreamOk(
69 response: Response,
70 requestUrl: string | URL,
71): Promise<Response> {
72 if (response.ok) return response;
73 const responseBody = await response.text();
74 const rawMessage =
75 extractUpstreamMessage(responseBody) ||
76 getDefaultErrorMessage(response.status);
77 throw new UpstreamError(remapUpstreamStatus(response.status), {
78 message: truncateString(rawMessage, MAX_ERROR_MESSAGE_LENGTH) ?? "",
79 requestUrl:
80 typeof requestUrl === "string" ? new URL(requestUrl) : requestUrl,
81 upstreamStatus: response.status,
82 responseBody,
83 });
84}
85
86function extractUpstreamMessage(body: string): string {
87 try {

Callers 15

callOpenAIEmbedFunction · 0.90
callCohereAzureEmbedFunction · 0.90
callGeminiEmbedFunction · 0.90
callFireworksEmbedFunction · 0.90
uploadAssemblyAiFileFunction · 0.90
pollAssemblyAiTranscriptFunction · 0.90
fetchAssemblyAiSubtitlesFunction · 0.90
generateSpeechFunction · 0.90
transcribeWithElevenLabsFunction · 0.90
uploadMusicReferenceFunction · 0.90
generateMusicFunction · 0.90

Calls 5

extractUpstreamMessageFunction · 0.85
getDefaultErrorMessageFunction · 0.85
remapUpstreamStatusFunction · 0.85
truncateStringFunction · 0.85
textMethod · 0.65

Tested by

no test coverage detected