Skip to content

Commit 62552a2

Browse files
committed
do not log abort errors during chat message stream
1 parent 3a5ce74 commit 62552a2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/ai/src/methods/chat-session.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ export class ChatSession {
191191
// Errors in streamPromise are already catchable by the user as
192192
// streamPromise is returned.
193193
// Avoid duplicating the error message in logs.
194-
if (e.message !== SILENT_ERROR) {
194+
// AbortErrors are thrown after the initial streamPromise resolves, since the request
195+
// may be aborted once streaming has begun. Since these errors won't be wrapped in a SILENT_ERROR,
196+
// we have to explicitly check for them. The user will be able to catch these AbortErrors when
197+
// awaiting the resolution of the result.response.
198+
if (e.message !== SILENT_ERROR && e.name !== 'AbortError') {
195199
// Users do not have access to _sendPromise to catch errors
196200
// downstream from streamPromise, so they should not throw.
197201
logger.error(e);

0 commit comments

Comments
 (0)