🔧 fix: Error Handling Improvements (#1518)

* style(Icon): remove error bubble from message icon

* fix(custom): `initializeClient` now throws error if apiKey or baseURL are admin provided but no env var was found

* refactor(tPresetSchema): match `conversationId` type to `tConversationSchema` but optional, use `extendedModelEndpointSchema` for `endpoint`

* fix(useSSE): minor improvements
- use `completed` set to avoid submitting unecessary abort request
- set preset with `newConversation` calls using initial conversation settings to prevent default Preset override as well as default settings
- return if there is a parsing error within `onerror` as expected errors from server are properly formatted
This commit is contained in:
Danny Avila 2024-01-08 09:30:38 -05:00 committed by GitHub
parent c9aaf502af
commit ead1c3c797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 14 deletions

View file

@ -4,6 +4,8 @@ const { isUserProvided, extractEnvVariable } = require('~/server/utils');
const getCustomConfig = require('~/cache/getCustomConfig');
const { OpenAIClient } = require('~/app');
const envVarRegex = /^\${(.+)}$/;
const { PROXY } = process.env;
const initializeClient = async ({ req, res, endpointOption }) => {
@ -20,6 +22,14 @@ const initializeClient = async ({ req, res, endpointOption }) => {
const CUSTOM_API_KEY = extractEnvVariable(endpointConfig.apiKey);
const CUSTOM_BASE_URL = extractEnvVariable(endpointConfig.baseURL);
if (CUSTOM_API_KEY.match(envVarRegex)) {
throw new Error(`Missing API Key for ${endpoint}.`);
}
if (CUSTOM_BASE_URL.match(envVarRegex)) {
throw new Error(`Missing Base URL for ${endpoint}.`);
}
const customOptions = {
addParams: endpointConfig.addParams,
dropParams: endpointConfig.dropParams,