Fix quota error async-ness

This commit is contained in:
Cohee 2024-11-24 01:48:08 +02:00
parent 70c45fb001
commit df50fece6c

View File

@ -1326,7 +1326,7 @@ function tryParseStreamingError(response, decoded) {
return; return;
} }
void checkQuotaError(data); checkQuotaError(data);
checkModerationError(data); checkModerationError(data);
// these do not throw correctly (equiv to Error("[object Object]")) // these do not throw correctly (equiv to Error("[object Object]"))
@ -1350,18 +1350,16 @@ function tryParseStreamingError(response, decoded) {
/** /**
* Checks if the response contains a quota error and displays a popup if it does. * Checks if the response contains a quota error and displays a popup if it does.
* @param data * @param data
* @returns {Promise<void>} * @returns {void}
* @throws {object} - response JSON * @throws {object} - response JSON
*/ */
async function checkQuotaError(data) { function checkQuotaError(data) {
const errorText = await renderTemplateAsync('quotaError');
if (!data) { if (!data) {
return; return;
} }
if (data.quota_error) { if (data.quota_error) {
callPopup(errorText, 'text'); renderTemplateAsync('quotaError').then((html) => Popup.show.text('Quota Error', html));
// this does not throw correctly (equiv to Error("[object Object]")) // this does not throw correctly (equiv to Error("[object Object]"))
// if trying to fix "[object Object]" displayed to users, start here // if trying to fix "[object Object]" displayed to users, start here
@ -2054,7 +2052,7 @@ async function sendOpenAIRequest(type, messages, signal) {
else { else {
const data = await response.json(); const data = await response.json();
await checkQuotaError(data); checkQuotaError(data);
checkModerationError(data); checkModerationError(data);
if (data.error) { if (data.error) {