Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion open-sse/handlers/imageGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
extractComfyOutputFiles,
} from "../utils/comfyuiClient.ts";
import { fetchRemoteImage } from "@/shared/network/remoteImageFetch";
import { fetchWithTimeout, getConfiguredTimeout } from "@/shared/utils/fetchTimeout";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to Rule 9 of the Repository Style Guide, we must always include tests when changing production code in open-sse/. Please add unit tests to verify the new timeout behavior of fetchImageEndpoint and ensure that fetchWithTimeout is correctly invoked with the configured timeout.

Suggested change
import { fetchWithTimeout, getConfiguredTimeout } from "@/shared/utils/fetchTimeout";
import { fetchWithTimeout, getConfiguredTimeout, FetchTimeoutError } from "@/shared/utils/fetchTimeout";
References
  1. Always include tests when changing production code (src/, open-sse/, electron/, bin/). (link)

import { sanitizeErrorMessage, sanitizeUpstreamDetails } from "../utils/error.ts";

interface KieImageOptions {
Expand Down Expand Up @@ -2414,10 +2415,11 @@ function saveImageErrorResult({ provider, model, status, startTime, error, reque
*/
async function fetchImageEndpoint(url, headers, body, provider, log) {
try {
const response = await fetch(url, {
const response = await fetchWithTimeout(url, {
method: "POST",
headers,
body,
timeoutMs: getConfiguredTimeout(),
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When an upstream image generation request times out, returning a 502 (Bad Gateway) status code is misleading. To align with other timeout handlers in this file (which return 504), we should catch FetchTimeoutError or AbortError and return a 504 (Gateway Timeout) status code.

    let response;
    try {
      response = await fetchWithTimeout(url, {
        method: "POST",
        headers,
        body,
        timeoutMs: getConfiguredTimeout(),
      });
    } catch (err: any) {
      if (err instanceof FetchTimeoutError || err?.name === "AbortError") {
        if (log) {
          log.error("IMAGE", `${provider} fetch error: ${err.message}`);
        }
        return {
          success: false,
          status: 504,
          error: `Image provider error: ${sanitizeErrorMessage(err.message || err)}`,
        };
      }
      throw err;
    }


if (!response.ok) {
Expand Down