From c2e96621800cde4f48efb2f3e37770c0d1ea8980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Fri, 19 Jan 2018 13:24:32 +0100 Subject: [PATCH] Catch all error handling. We're gonna incrementally implement the error handling afterwards. --- weechat-matrix.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/weechat-matrix.py b/weechat-matrix.py index dbe7cf9..b611fda 100644 --- a/weechat-matrix.py +++ b/weechat-matrix.py @@ -585,9 +585,6 @@ def handle_http_response(server, message): # TODO handle try again response elif status_code == 504: pass - # TODO handle error responses - elif status_code == 401: - pass elif status_code == 403: if message.type == MessageType.LOGIN: response = decode_json(server, message.response.body) @@ -604,13 +601,31 @@ def handle_http_response(server, message): close_socket(server) disconnect(server) + elif message.type == MessageType.STATE: + response = decode_json(server, message.response.body) + reason = ("." if not response or not response["error"] else + ": {r}.".format(r=response["error"])) + + message = ("{prefix}Can't set state{reason}").format( + prefix=W.prefix("network"), + reason=reason) + server_buffer_prnt(server, message) + else: + message = ("{prefix}Unhandled 403 error, please inform the " + "developers about this: {error}").format( + prefix=W.prefix("error"), + error=message.response.body) + server_buffer_prnt(server, message) + else: server_buffer_prnt( server, - "ERROR IN HTTP RESPONSE {status_code}".format( + ("{prefix}Unhandled {status_code} error, please inform " + "the developers about this.").format( + prefix=W.prefix("error"), status_code=status_code)) - server_buffer_prnt(server, pprint.pformat(message.request.request)) + server_buffer_prnt(server, pprint.pformat(message.type)) server_buffer_prnt(server, pprint.pformat(message.request.payload)) server_buffer_prnt(server, pprint.pformat(message.response.body))