changeset 31:e561bdd81777

Display better vCard4 errors.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 23 Dec 2018 18:20:17 +0100
parents 9ba4f8cc32f1
children b15e1581c3d4
files vcard.js
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/vcard.js
+++ b/vcard.js
@@ -14,17 +14,17 @@ function initVCard(connection) {
         .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
             .c('items', {node: 'urn:xmpp:vcard4'})
                 .c('item', {id: 'current'});
-    connection.sendIQ(iq, onVCard4, onVCard4RetrievalError.bind(null, 'PubSub query failed.'));
+    connection.sendIQ(iq, onVCard4, onVCard4RetrievalError);
     displaySpinner(spinner_img);
 
     function onVCard4(result_iq)
     {
         const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item');
         if (item === null)
-            return onVCard4RetrievalError('no item found.');
+            return onVCard4RetrievalError(null, 'no item found.');
         const vcard = parseXPath(item, './vcard4:vcard');
         if (vcard === null)
-            return onVCard4RetrievalError('no vCard4 found, your PubSub node is broken.');
+            return onVCard4RetrievalError(null, 'no vCard4 found, your PubSub node is broken.');
 
         vcard_data.fn = parseXPathText(vcard, './vcard4:fn/vcard4:text');
         vcard_data.email = parseXPathText(vcard, './vcard4:email/vcard4:text');
@@ -39,9 +39,14 @@ function initVCard(connection) {
         hideSpinner(spinner_img);
     }
 
-    function onVCard4RetrievalError(string)
+    function onVCard4RetrievalError(iq, string)
     {
-        console.log('Failed to retrieve vCard4: ' + string);
+        if (!string) {
+            const [condition, text] = parseErrorIq(iq);
+            const string = condition + ': ' + text;
+        }
+        string = 'Failed to retrieve vCard4: ' + string;
+        console.log(string);
         vcard_fn.disabled = false;
         vcard_email.disabled = false;
         vcard_bday.disabled = false;