From 81165c400742259185fad65910980c599e76ce1d Mon Sep 17 00:00:00 2001 From: aldemylla Date: Tue, 2 Apr 2024 15:20:38 -0300 Subject: [PATCH] feat: Added error if VITE_GPT_URL not exist --- src/services/api/resources/GPT.js | 6 ++++++ src/utils/env.js | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/services/api/resources/GPT.js b/src/services/api/resources/GPT.js index b5bf3aca..8e63a477 100644 --- a/src/services/api/resources/GPT.js +++ b/src/services/api/resources/GPT.js @@ -9,6 +9,12 @@ const http = axios.create({ export default { async getInsights(prompt) { + if (!env('VITE_GPT_URL')) { + throw new Error( + `The VITE_GPT_URL environment variable is empty: ${env('VITE_GPT_URL')}`, + ); + } + const response = await http.post(env('VITE_GPT_URL'), { input: { prompt: `[INST] ${prompt} [/INST]`, diff --git a/src/utils/env.js b/src/utils/env.js index 9c012dcf..c10ce855 100644 --- a/src/utils/env.js +++ b/src/utils/env.js @@ -1,7 +1,9 @@ export default function env(name) { - return import.meta.env[name] || - window?.configs?.[name] || - process.env[name] || - window?.configs?.[`VITE_${name}`] || - process.env[`VITE_${name}`]; + return ( + import.meta.env?.[name] || + window?.configs?.[name] || + process.env[name] || + window?.configs?.[`VITE_${name}`] || + process.env[`VITE_${name}`] + ); }