]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/error.js
Merge branch '3.6-release'
[friendica-addons.git] / jappixmini / jappix / js / error.js
1 /*
2
3 Jappix - An open social platform
4 These are the error functions for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Author: Vanaryon
10 Last revision: 02/04/11
11
12 */
13
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
19                 var eText = '';
20                 
21                 // Any error condition
22                 if(condition)
23                         eText += condition;
24                 
25                 // Any error type
26                 if(type && eText)
27                         eText += ' (' + type + ')';
28                 
29                 // Any error reason
30                 if(reason) {
31                         if(eText)
32                                 eText += ' - ';
33                         
34                         eText += reason;
35                 }
36                 
37                 // We reveal the error
38                 openThisError(1);
39                 
40                 // Create the error text
41                 $('#board .one-board.error[data-id=1] span').text(eText);
42         }
43         
44         // Not enough data to output the error: output a generic board
45         else
46                 openThisError(2);
47 }
48
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 */
52         
53         // Initialize
54         var type, code, reason, condition;
55         var node = $(packet);
56         
57         // First level error (connection error)
58         if(node.is('error')) {
59                 // Get the value
60                 code = node.attr('code');
61                 
62                 // Specific error reason
63                 switch(code) {
64                         case '401':
65                                 reason = _e("Authorization failed");
66                                 break;
67                         
68                         case '409':
69                                 reason = _e("Registration failed, please choose a different username");
70                                 break;
71                         
72                         case '503':
73                                 reason = _e("Service unavailable");
74                                 break;
75                         
76                         case '500':
77                                 reason = _e("Internal server error, try later");
78                                 break;
79                         
80                         default:
81                                 reason = node.find('text').text();
82                                 break;
83                 }
84                 
85                 // Remove the general wait item (security)
86                 removeGeneralWait();
87                 
88                 // Show reconnect pane
89                 if(CURRENT_SESSION && CONNECTED) {
90                         // Anonymous?
91                         if(isAnonymous())
92                                 createReconnect('anonymous');
93                         else
94                                 createReconnect('normal');
95                 }
96                 
97                 // Show the homepage (security)
98                 else if(!CURRENT_SESSION || !CONNECTED) {
99                         $('#home').show();
100                         pageTitle('home');
101                 }
102                 
103                 // Still connected? (security)
104                 if(isConnected())
105                         con.disconnect();
106                 
107                 logThis('First level error received.', 1);
108         }
109         
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, ' ');
115                 
116                 logThis('Second level error received.', 1);
117         }
118         
119         // No error
120         else
121                 return false;
122         
123         // Show the error board
124         showError(condition, reason, type);
125         
126         // Return there's an error
127         return true;
128 }
129
130 // Handles the error reply of a packet
131 function handleErrorReply(packet) {
132         return handleError(packet.getNode());
133 }
134
135 // Handles the error reply for a message
136 function handleMessageError(packet) {
137         if(!handleErrorReply(packet))
138                 handleMessage(packet);
139 }