Worklog for task "Develop error handler for AI chat"

2 окт. 2026 г., 22:06:31

Here is what ChatGPT says:

Yes, a request abortion in the browser can lead to the cancellation of generation at the provider's end — if your backend links these two connections and passes the cancellation downstream. However, the lack of streaming response support in modern Chrome is an unlikely cause: fetch() supports reading responses via ReadableStream. MDN

Here we need to separate two segments: browser → your server and your server → provider. If the browser aborted the request, the server can cancel the request to the provider using AbortController. In that case, the error handler might indeed mistake this cancellation for "the provider interrupted the generation." The error text alone does not prove who aborted the connection first. Cancellation via AbortSignal can terminate an HTTP request with an AbortError. Node.js v26.10.0 Documentation

You can check API availability directly in the browser console:

const supportsResponseStreaming =
  typeof fetch === 'function' &&
  typeof ReadableStream === 'function' &&
  typeof Response === 'function' &&
  'body' in Response.prototype &&
  typeof ReadableStream.prototype.getReader === 'function';

console.log({ supportsResponseStreaming });

This checks support for reading a streaming response. There is no separate browser function called "HTTP Streamable supported"; if we are talking about a regular request with JSON and a streaming agent response, this exact capability is needed. Streaming request body sending is a different capability with its own limitations. MDN

But true does not guarantee that the stream passes normally through the entire chain. For this, you need a test endpoint on your server that sends, for example, five messages at one-second intervals, and a check in the browser:

async function testStream(url) {
  const started = performance.now();
  const response = await fetch(url, { cache: 'no-store' });

  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  if (!response.body) throw new Error('No response body');

  const reader = response.body.getReader();

  try {
    while (true) {
      const { done, value } = await reader.read();
      if (done) break;

      console.log({
        elapsedMs: Math.round(performance.now() - started),
        bytes: value.byteLength,
      });
    }
    console.log('Stream completed');
  } catch (error) {
    console.error('Error reading stream:', error);
  } finally {
    reader.releaseLock();
  }
}

testStream('/api/stream-test');

The address here is conditional — the endpoint needs to be implemented. Reading via getReader() allows you to observe the arrival of response chunks. Network chunk boundaries do not have to match server message boundaries. MDN

Interpretation:

  • Chunks arrive gradually — the stream is going through.
  • Everything arrives in one chunk at the end — buffering is happening somewhere.
  • Reading fails with an error — the connection or stream processing is broken; the cause requires correlation with the server log.

For your case, the decisive check is the order of events in the logs of a single request: client disconnection, calling request cancellation to the provider, provider response reading error. If the client disconnects first and then your code cancels the generation, the hypothesis is confirmed. If the stream from the provider is corrupted first, the cause lies in a different segment.

The "laptop / mobile" difference by itself only indicates a difference in conditions: network, VPN, extensions, frontend version, or its request cancellation logic. It is not possible to pinpoint a specific cause based on this sign alone.

02.10.2026