chore: completions error handler

This commit is contained in:
jialin
2025-01-16 14:25:03 +08:00
parent 4a748e894d
commit 4a838e7bdb
8 changed files with 72 additions and 10 deletions
+18 -3
View File
@@ -24,6 +24,21 @@ const extractJSON = (dataStr: string) => {
return results;
};
const errorHandler = async (res: any) => {
try {
const data = await res.json();
return {
error: true,
data: data
};
} catch (error) {
return {
error: true,
message: res.statusText
};
}
};
/**
*
* @param params data: for post request, params: for get request
@@ -51,11 +66,11 @@ export const fetchChunkedData = async (params: {
...params.headers
}
});
console.log('response====', response);
if (!response.ok) {
return {
error: true,
data: await response.json()
data: await errorHandler(response)
};
}
const reader = response?.body?.getReader();
@@ -107,7 +122,7 @@ export const fetchChunkedDataPostFormData = async (params: {
if (!response.ok) {
return {
error: true,
data: await response.json()
data: await errorHandler(response)
};
}
const reader = response?.body?.getReader();