Skip to content

Commit

Permalink
Recognize a few more OpenAI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jul 30, 2023
1 parent 6cfe7cc commit d55adb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/extensions/chatgpt-web/chatgpt-web-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ export default class ChatGPTWebAPI extends ChatConversationAPI<SessionData> {
});

// Error happened.
if (response.status == 403)
throw new APIError('Access token expired.', 'refresh');
if (response.status == 401)
throw new APIError('Authentication token expired.', 'relogin');
if (response.status == 403)
throw new APIError('Access token expired.', 'refresh');
if (response.status == 418)
throw new APIError('Require human validation.', 'refresh');
if (response.status != 200) {
const detail = (await response.json()).detail;
if (typeof detail == 'string')
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/chatgpt/chatgpt-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class ChatGPTAPI extends ChatCompletionAPI {
const body = await response.json();
if (!body.error)
throw new APIError(`Unexpected open from ChatGPT API: ${body}`);
if (body.error.message.includes('You exceeded your current quota'))
throw new APIError(body.error.message + ' (This error can usually be solved by linking a valid credit card to your OpenAI account.)');
throw new APIError(body.error.message);
}

Expand Down

0 comments on commit d55adb4

Please sign in to comment.