Fix quota error async-ness

df50fece6c47ca85ee15d9f69ab2d082090e403f

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +5 -7Showing whitespace changes
public/scripts/openai.js+5 -7
@@ -1326,7 +1326,7 @@ function tryParseStreamingError(response, decoded) {
1326 return;1326 return;
1327 }1327 }
13281328
1329 void checkQuotaError(data);1329 checkQuotaError(data);
1330 checkModerationError(data);1330 checkModerationError(data);
13311331
1332 // these do not throw correctly (equiv to Error("[object Object]"))1332 // these do not throw correctly (equiv to Error("[object Object]"))
@@ -1350,18 +1350,16 @@ function tryParseStreamingError(response, decoded) {
1350/**1350/**
1351 * Checks if the response contains a quota error and displays a popup if it does.1351 * Checks if the response contains a quota error and displays a popup if it does.
1352 * @param data1352 * @param data
1353 * @returns {Promise<void>}1353 * @returns {void}
1354 * @throws {object} - response JSON1354 * @throws {object} - response JSON
1355 */1355 */
1356async function checkQuotaError(data) {1356function checkQuotaError(data) {
1357 const errorText = await renderTemplateAsync('quotaError');
1358
1359 if (!data) {1357 if (!data) {
1360 return;1358 return;
1361 }1359 }
13621360
1363 if (data.quota_error) {1361 if (data.quota_error) {
1364 callPopup(errorText, 'text');1362 renderTemplateAsync('quotaError').then((html) => Popup.show.text('Quota Error', html));
13651363
1366 // this does not throw correctly (equiv to Error("[object Object]"))1364 // this does not throw correctly (equiv to Error("[object Object]"))
1367 // if trying to fix "[object Object]" displayed to users, start here1365 // if trying to fix "[object Object]" displayed to users, start here
@@ -2054,7 +2052,7 @@ async function sendOpenAIRequest(type, messages, signal) {
2054 else {2052 else {
2055 const data = await response.json();2053 const data = await response.json();
20562054
2057 await checkQuotaError(data);2055 checkQuotaError(data);
2058 checkModerationError(data);2056 checkModerationError(data);
20592057
2060 if (data.error) {2058 if (data.error) {