server: Handle http error responses.
This commit is contained in:
parent
df61dba644
commit
9e6bd0c246
2 changed files with 20 additions and 6 deletions
4
main.py
4
main.py
|
@ -35,7 +35,7 @@ import logbook
|
||||||
from logbook import Logger, StderrHandler, StreamHandler
|
from logbook import Logger, StderrHandler, StreamHandler
|
||||||
|
|
||||||
import nio
|
import nio
|
||||||
from nio import TransportType, RemoteTransportError
|
from nio import TransportType, RemoteTransportError, RemoteProtocolError
|
||||||
|
|
||||||
from matrix.colors import Formatted
|
from matrix.colors import Formatted
|
||||||
from matrix.utf import utf8_decode
|
from matrix.utf import utf8_decode
|
||||||
|
@ -298,7 +298,7 @@ def receive_cb(server_name, file_descriptor):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
server.client.receive(data)
|
server.client.receive(data)
|
||||||
except RemoteTransportError as e:
|
except (RemoteTransportError, RemoteProtocolError) as e:
|
||||||
server.error(str(e))
|
server.error(str(e))
|
||||||
server.disconnect()
|
server.disconnect()
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,13 @@ import pprint
|
||||||
|
|
||||||
from collections import deque, defaultdict
|
from collections import deque, defaultdict
|
||||||
|
|
||||||
from nio import HttpClient, LoginResponse, SyncRepsponse
|
from nio import (
|
||||||
|
HttpClient,
|
||||||
|
LoginResponse,
|
||||||
|
SyncRepsponse,
|
||||||
|
TransportResponse,
|
||||||
|
LocalProtocolError
|
||||||
|
)
|
||||||
|
|
||||||
from matrix.plugin_options import Option, DebugType
|
from matrix.plugin_options import Option, DebugType
|
||||||
from matrix.utils import (key_from_value, prnt_debug, server_buffer_prnt,
|
from matrix.utils import (key_from_value, prnt_debug, server_buffer_prnt,
|
||||||
|
@ -284,7 +290,7 @@ class MatrixServer:
|
||||||
if self.server_buffer:
|
if self.server_buffer:
|
||||||
buf = self.server_buffer
|
buf = self.server_buffer
|
||||||
|
|
||||||
msg = "{prefix}{}: {}".format(SCRIPT_NAME, message)
|
msg = "{}{}: {}".format(W.prefix("network"), SCRIPT_NAME, message)
|
||||||
W.prnt(buf, msg)
|
W.prnt(buf, msg)
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
|
@ -343,7 +349,11 @@ class MatrixServer:
|
||||||
|
|
||||||
self.send_buffer = b""
|
self.send_buffer = b""
|
||||||
self.current_message = None
|
self.current_message = None
|
||||||
|
|
||||||
|
try:
|
||||||
self.client.disconnect()
|
self.client.disconnect()
|
||||||
|
except LocalProtocolError:
|
||||||
|
pass
|
||||||
|
|
||||||
self.lag = 0
|
self.lag = 0
|
||||||
W.bar_item_update("lag")
|
W.bar_item_update("lag")
|
||||||
|
@ -491,8 +501,12 @@ class MatrixServer:
|
||||||
|
|
||||||
def handle_response(self, response):
|
def handle_response(self, response):
|
||||||
# type: (MatrixMessage) -> None
|
# type: (MatrixMessage) -> None
|
||||||
|
if isinstance(response, TransportResponse):
|
||||||
|
self.error("Error in response, code: {}".format(
|
||||||
|
response.status_code))
|
||||||
|
self.disconnect()
|
||||||
|
|
||||||
if isinstance(response, LoginResponse):
|
elif isinstance(response, LoginResponse):
|
||||||
self._handle_login(response)
|
self._handle_login(response)
|
||||||
elif isinstance(response, SyncRepsponse):
|
elif isinstance(response, SyncRepsponse):
|
||||||
self._handle_sync(response)
|
self._handle_sync(response)
|
||||||
|
|
Loading…
Reference in a new issue