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:
Classic298
2025-12-31 14:40:56 +01:00
committed by GitHub
parent 252a983091
commit 0bd295b10b

View File

@@ -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[]) => {