3 Jappix - An open social platform
4 These are the error functions for Jappix
6 -------------------------------------------------
10 Last revision: 02/04/11
14 // Shows the given error output
15 function showError(condition, reason, type) {
16 // Enough data to output the error
17 if(condition || reason) {
18 // Initialize the error text
21 // Any error condition
27 eText += ' (' + type + ')';
37 // We reveal the error
40 // Create the error text
41 $('#board .one-board.error[data-id=1] span').text(eText);
44 // Not enough data to output the error: output a generic board
49 // Handles the error from a packet and return true if any error
50 function handleError(packet) {
51 /* REF: http://xmpp.org/extensions/xep-0086.html */
54 var type, code, reason, condition;
57 // First level error (connection error)
58 if(node.is('error')) {
60 code = node.attr('code');
62 // Specific error reason
65 reason = _e("Authorization failed");
69 reason = _e("Registration failed, please choose a different username");
73 reason = _e("Service unavailable");
77 reason = _e("Internal server error, try later");
81 reason = node.find('text').text();
85 // Remove the general wait item (security)
88 // Show reconnect pane
89 if(CURRENT_SESSION && CONNECTED) {
92 createReconnect('anonymous');
94 createReconnect('normal');
97 // Show the homepage (security)
98 else if(!CURRENT_SESSION || !CONNECTED) {
103 // Still connected? (security)
107 logThis('First level error received.', 1);
110 // Second level error (another error)
111 else if(node.find('error').size()) {
112 type = node.find('error').attr('type');
113 reason = node.find('error text').text();
114 condition = packet.getElementsByTagName('error').item(0).childNodes.item(0).nodeName.replace(/-/g, ' ');
116 logThis('Second level error received.', 1);
123 // Show the error board
124 showError(condition, reason, type);
126 // Return there's an error
130 // Handles the error reply of a packet
131 function handleErrorReply(packet) {
132 return handleError(packet.getNode());
135 // Handles the error reply for a message
136 function handleMessageError(packet) {
137 if(!handleErrorReply(packet))
138 handleMessage(packet);