fix: prevent getOpenAIUrls and getOpenAIKeys crash on null response (#20272)
Use optional chaining and nullish coalescing when accessing res.OPENAI_API_BASE_URLS and res.OPENAI_API_KEYS. Returns empty array instead of crashing with 'Cannot read property of null'.
This commit is contained in:
@@ -103,7 +103,7 @@ export const getOpenAIUrls = async (token: string = '') => {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.OPENAI_API_BASE_URLS;
|
||||
return res?.OPENAI_API_BASE_URLS ?? [];
|
||||
};
|
||||
|
||||
export const updateOpenAIUrls = async (token: string = '', urls: string[]) => {
|
||||
@@ -170,7 +170,7 @@ export const getOpenAIKeys = async (token: string = '') => {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res.OPENAI_API_KEYS;
|
||||
return res?.OPENAI_API_KEYS ?? [];
|
||||
};
|
||||
|
||||
export const updateOpenAIKeys = async (token: string = '', keys: string[]) => {
|
||||
|
||||
Reference in New Issue
Block a user