Skip to content

Commit 4ebe473

Browse files
committed
Show client HTTP errors
1 parent 4995e7e commit 4ebe473

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/chatgpt_gui/gui/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ def _connect_events(self) -> None:
225225
self.updateTranslations.connect(self._registered_translations)
226226
self.updateTranslations.connect(self._translate_http_code_map)
227227

228+
self.client.receivedError.connect(
229+
lambda code: self.show_dialog('errors.client_http_error',
230+
title_args=(http_code_map[code][0],),
231+
description_args=(code, http_code_map[code][1])))
232+
228233
self.client.authenticationRequired.connect(
229234
lambda: self.show_dialog('warnings.empty_token'))
230235

src/chatgpt_gui/gui/windows/application.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ def show(self) -> None:
211211
app().windows['readme_viewer'].show()
212212
app().show_dialog('information.first_launch', self)
213213

214-
QTimer(self).singleShot(200, self.update_user_icon)
214+
if app().client.session_token:
215+
QTimer(self).singleShot(200, self.update_user_icon)
216+
else:
217+
app().client.authenticationRequired.emit()
215218

216219
def closeEvent(self, event: QCloseEvent) -> None:
217220
"""Close all detached/children windows and quit application."""

src/chatgpt_gui/network/client/chatgpt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Client(QObject):
3737
"""Asynchronous HTTP REST Client that interfaces with ChatGPT."""
3838

3939
authenticationRequired = Signal()
40+
receivedError = Signal(int)
4041
receivedMessage = Signal(Message, Conversation)
4142
signedOut = Signal()
4243

@@ -274,6 +275,8 @@ def _get(self, path: str, update_auth_on_401: bool = True, **kwargs) -> Response
274275
if response.code == 401:
275276
# Refresh auth failed, ask user to re-authenticate.
276277
self.authenticationRequired.emit()
278+
elif response.code != 401:
279+
self.receivedError.emit(response.code)
277280

278281
return response
279282

@@ -357,6 +360,9 @@ def send_message(self, message_text: str, conversation: Conversation) -> None:
357360
)
358361

359362
response: Response = request.send(self.session, wait_until_finished=True)
363+
if not response.ok:
364+
self.receivedError.emit(response.code)
365+
return
360366

361367
# Get the finished stream from the text/event-stream
362368
# Index -1 Is empty string, as the response ends with 2 newlines

0 commit comments

Comments
 (0)