fix: Add better error handling for chat errors (#10408)

This commit is contained in:
Mutasem Aldmour 2024-08-14 16:17:32 +02:00 committed by GitHub
parent 80c96a3dcc
commit f82b6e4ba9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,7 @@ import { ApplicationError, jsonParse, type GenericValue, type IDataObject } from
import type { IExecutionFlattedResponse, IExecutionResponse, IRestApiContext } from '@/Interface';
import { parse } from 'flatted';
import type { ChatRequest } from '@/types/assistant.types';
import { assert } from '@/utils/assert';
const BROWSER_ID_STORAGE_KEY = 'n8n-browserId';
let browserId = localStorage.getItem(BROWSER_ID_STORAGE_KEY);
@ -214,6 +215,7 @@ export const streamRequest = async (
credentials: 'include',
body: JSON.stringify(payload),
};
try {
const response = await fetch(`${context.baseUrl}${apiEndpoint}`, assistantRequest);
if (response.ok && response.body) {
@ -251,4 +253,8 @@ export const streamRequest = async (
} else if (onError) {
onError(new Error(response.statusText));
}
} catch (e: unknown) {
assert(e instanceof Error);
onError?.(e);
}
};