Commit bfa0a90a authored by Skippy's avatar Skippy

Fix double call to refreshSession() on 403

parent 1090fd8a
...@@ -32,6 +32,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -32,6 +32,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
protected _browser: Browser protected _browser: Browser
protected _page: Page protected _page: Page
protected _proxyServer: string protected _proxyServer: string
protected _isRefreshing: boolean
/** /**
* Creates a new client for automating the ChatGPT webapp. * Creates a new client for automating the ChatGPT webapp.
...@@ -95,6 +96,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -95,6 +96,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
this._nopechaKey = nopechaKey this._nopechaKey = nopechaKey
this._executablePath = executablePath this._executablePath = executablePath
this._proxyServer = proxyServer this._proxyServer = proxyServer
this._isRefreshing = false
if (!this._email) { if (!this._email) {
const error = new types.ChatGPTError('ChatGPT invalid email') const error = new types.ChatGPTError('ChatGPT invalid email')
...@@ -280,7 +282,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -280,7 +282,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
} }
if (url.endsWith('/conversation')) { if (url.endsWith('/conversation')) {
if (status === 403) { if (status === 403 && !this._isRefreshing) {
await this.refreshSession() await this.refreshSession()
} }
} else if (url.endsWith('api/auth/session')) { } else if (url.endsWith('api/auth/session')) {
...@@ -327,6 +329,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -327,6 +329,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
* Attempts to handle 403 errors by refreshing the page. * Attempts to handle 403 errors by refreshing the page.
*/ */
async refreshSession() { async refreshSession() {
this._isRefreshing = true
console.log(`ChatGPT "${this._email}" session expired (403); refreshing...`) console.log(`ChatGPT "${this._email}" session expired (403); refreshing...`)
try { try {
if (!this._minimize) { if (!this._minimize) {
...@@ -372,6 +375,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -372,6 +375,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
`ChatGPT "${this._email}" error refreshing session`, `ChatGPT "${this._email}" error refreshing session`,
err.toString() err.toString()
) )
} finally {
this._isRefreshing = false
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment