Download src/http/core/stream-errors.ts from xjackkx/s2: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/xjackkx/s2/resolve/main/src/http/core/stream-errors.ts
- Command line
-
hf download hf://spaces/xjackkx/s2/src/http/core/stream-errors.ts
-
curl -L -o stream-errors.ts https://huggingface.co/spaces/xjackkx/s2/resolve/main/src/http/core/stream-errors.ts
1.05 kB
| import { upstreamErrorCode, upstreamErrorMessage } from "../../shared/errors"; | |
| import type { SSEWrite } from "./sse"; | |
| export function streamErrorText(e: unknown, prefix = "upstream error"): string { | |
| const code = upstreamErrorCode(e); | |
| return `⚠️ ${prefix}: ${upstreamErrorMessage(e)}${code ? ` [${code}]` : ""}`; | |
| } | |
| export function streamInterruptedWarningText(e: unknown): string { | |
| return streamErrorText(e, "stream interrupted after partial output"); | |
| } | |
| export function streamWarningObject( | |
| e: unknown, | |
| message: unknown = undefined, | |
| ): { code: string; message: unknown } { | |
| return { | |
| code: upstreamErrorCode(e) || "stream_interrupted", | |
| message: message || streamInterruptedWarningText(e), | |
| }; | |
| } | |
| export async function writeStreamWarningEvent( | |
| write: SSEWrite, | |
| e: unknown, | |
| message: unknown = undefined, | |
| ): Promise<void> { | |
| const result = write( | |
| `event: warning\ndata: ${JSON.stringify({ warning: streamWarningObject(e, message) })}\n\n`, | |
| ); | |
| if (result && typeof (result as Promise<void>).then === "function") | |
| await result; | |
| } | |