|
|
|
@ -30,8 +30,8 @@ export async function requestOpenai(req: NextRequest) {
|
|
|
|
|
controller.abort();
|
|
|
|
|
}, 10 * 60 * 1000);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return await fetch(`${baseUrl}/${openaiPath}`, {
|
|
|
|
|
const fetchUrl = `${baseUrl}/${openaiPath}`;
|
|
|
|
|
const fetchOptions: RequestInit = {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
Authorization: authValue,
|
|
|
|
@ -43,13 +43,17 @@ export async function requestOpenai(req: NextRequest) {
|
|
|
|
|
method: req.method,
|
|
|
|
|
body: req.body,
|
|
|
|
|
signal: controller.signal,
|
|
|
|
|
});
|
|
|
|
|
} catch (err: unknown) {
|
|
|
|
|
if (err instanceof Error && err.name === "AbortError") {
|
|
|
|
|
console.log("Fetch aborted");
|
|
|
|
|
} else {
|
|
|
|
|
throw err;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(fetchUrl, fetchOptions);
|
|
|
|
|
|
|
|
|
|
if (res.status === 401) {
|
|
|
|
|
// to prevent browser prompt for credentials
|
|
|
|
|
res.headers.delete("www-authenticate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
} finally {
|
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
|
}
|
|
|
|
|