comparison libervia/server/websockets.py @ 1206:d2e2bf14f2e2

server (websocket): don't crash if self.page doesn't exist while onClose is called
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2019 17:25:53 +0200
parents 251eba911d4d
children b2d067339de3
comparison
equal deleted inserted replaced
1205:92d0a2b785fd 1206:d2e2bf14f2e2
149 ) 149 )
150 else: 150 else:
151 cb(page, self.request, data_json) 151 cb(page, self.request, data_json)
152 152
153 def onClose(self, wasClean, code, reason): 153 def onClose(self, wasClean, code, reason):
154 self.page.onSocketClose(self.request) 154 try:
155 page = self.page
156 except AttributeError:
157 log.debug(
158 u"page is not available, the socket was probably not opened cleanly.\n"
159 u"reason: {reason}".format(reason=reason))
160 return
161 page.onSocketClose(self.request)
155 162
156 log.debug( 163 log.debug(
157 _( 164 _(
158 u"Websocket closed for {page} (token: {token}). {reason}".format( 165 u"Websocket closed for {page} (token: {token}). {reason}".format(
159 page=self.page, 166 page=self.page,