summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-06-18 15:48:19 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-06-18 15:48:19 +0200
commit77a2165639e3ba49c84496a4b7ae22908fb2bc9c (patch)
tree2018ecd759f5a7314579f7a6b671b3d8ec7b96b0
parentc51559b14f492d44664f3e9f8951943654c6e034 (diff)
downloadpoezio-77a2165639e3ba49c84496a4b7ae22908fb2bc9c.tar.gz
poezio-77a2165639e3ba49c84496a4b7ae22908fb2bc9c.tar.bz2
poezio-77a2165639e3ba49c84496a4b7ae22908fb2bc9c.tar.xz
poezio-77a2165639e3ba49c84496a4b7ae22908fb2bc9c.zip
Handler error messages even when not comming from a room
-rw-r--r--src/core.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/core.py b/src/core.py
index 1c675410..3f24fb1b 100644
--- a/src/core.py
+++ b/src/core.py
@@ -550,6 +550,8 @@ class Core(object):
jid = message['from']
body = xhtml.get_body_from_message_stanza(message)
if not body:
+ if message['type'] == 'error':
+ self.information(self.get_error_message_from_error_stanza(message), 'Error')
return
conversation = self.get_tab_of_conversation_with_jid(jid, create=True)
if roster.get_contact_by_jid(jid.bare):
@@ -851,26 +853,34 @@ class Core(object):
self.current_tab().on_scroll_up()
self.refresh_window()
- def room_error(self, error, room_name):
+ def get_error_message_from_error_stanza(self, stanza):
"""
- Display the error on the room window
+ Takes a stanza of the form <message type='error'><error/></message>
+ and return a well formed string containing the error informations
"""
- room = self.get_room_by_name(room_name)
- msg = error['error']['type']
- condition = error['error']['condition']
- code = error['error']['code']
- body = error['error']['text']
+ msg = stanza['error']['type']
+ condition = stanza['error']['condition']
+ code = stanza['error']['code']
+ body = stanza['error']['text']
if not body:
if code in ERROR_AND_STATUS_CODES:
body = ERROR_AND_STATUS_CODES[code]
else:
body = condition or _('Unknown error')
if code:
- msg = _('Error: %(code)s - %(msg)s: %(body)s') % {'msg':msg, 'body':body, 'code':code}
- self.add_message_to_text_buffer(room, msg)
+ message = _('Error: %(code)s - %(msg)s: %(body)s') % {'msg':msg, 'body':body, 'code':code}
else:
- msg = _('Error: %(msg)s: %(body)s') % {'msg':msg, 'body':body}
- self.add_message_to_text_buffer(room, msg)
+ message = _('Error: %(msg)s: %(body)s') % {'msg':msg, 'body':body}
+ return message
+
+ def room_error(self, error, room_name):
+ """
+ Display the error on the room window
+ """
+ room = self.get_room_by_name(room_name)
+ error_message = self.get_error_message_from_error_stanza(error)
+ self.add_message_to_text_buffer(room, error_message)
+ code = error['error']['code']
if code == '401':
msg = _('To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)')
self.add_message_to_text_buffer(room, msg)