Mercurial > xmpp-account-manager
comparison vcard.js @ 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 |
comparison
equal
deleted
inserted
replaced
30:9ba4f8cc32f1 | 31:e561bdd81777 |
---|---|
12 | 12 |
13 const iq = $iq({type: 'get'}) | 13 const iq = $iq({type: 'get'}) |
14 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | 14 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) |
15 .c('items', {node: 'urn:xmpp:vcard4'}) | 15 .c('items', {node: 'urn:xmpp:vcard4'}) |
16 .c('item', {id: 'current'}); | 16 .c('item', {id: 'current'}); |
17 connection.sendIQ(iq, onVCard4, onVCard4RetrievalError.bind(null, 'PubSub query failed.')); | 17 connection.sendIQ(iq, onVCard4, onVCard4RetrievalError); |
18 displaySpinner(spinner_img); | 18 displaySpinner(spinner_img); |
19 | 19 |
20 function onVCard4(result_iq) | 20 function onVCard4(result_iq) |
21 { | 21 { |
22 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); | 22 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); |
23 if (item === null) | 23 if (item === null) |
24 return onVCard4RetrievalError('no item found.'); | 24 return onVCard4RetrievalError(null, 'no item found.'); |
25 const vcard = parseXPath(item, './vcard4:vcard'); | 25 const vcard = parseXPath(item, './vcard4:vcard'); |
26 if (vcard === null) | 26 if (vcard === null) |
27 return onVCard4RetrievalError('no vCard4 found, your PubSub node is broken.'); | 27 return onVCard4RetrievalError(null, 'no vCard4 found, your PubSub node is broken.'); |
28 | 28 |
29 vcard_data.fn = parseXPathText(vcard, './vcard4:fn/vcard4:text'); | 29 vcard_data.fn = parseXPathText(vcard, './vcard4:fn/vcard4:text'); |
30 vcard_data.email = parseXPathText(vcard, './vcard4:email/vcard4:text'); | 30 vcard_data.email = parseXPathText(vcard, './vcard4:email/vcard4:text'); |
31 vcard_data.bday = parseXPathText(vcard, './vcard4:bday/vcard4:date'); | 31 vcard_data.bday = parseXPathText(vcard, './vcard4:bday/vcard4:date'); |
32 | 32 |
37 vcard_bday.value = vcard_data.bday; | 37 vcard_bday.value = vcard_data.bday; |
38 vcard_bday.disabled = false; | 38 vcard_bday.disabled = false; |
39 hideSpinner(spinner_img); | 39 hideSpinner(spinner_img); |
40 } | 40 } |
41 | 41 |
42 function onVCard4RetrievalError(string) | 42 function onVCard4RetrievalError(iq, string) |
43 { | 43 { |
44 console.log('Failed to retrieve vCard4: ' + string); | 44 if (!string) { |
45 const [condition, text] = parseErrorIq(iq); | |
46 const string = condition + ': ' + text; | |
47 } | |
48 string = 'Failed to retrieve vCard4: ' + string; | |
49 console.log(string); | |
45 vcard_fn.disabled = false; | 50 vcard_fn.disabled = false; |
46 vcard_email.disabled = false; | 51 vcard_email.disabled = false; |
47 vcard_bday.disabled = false; | 52 vcard_bday.disabled = false; |
48 hideSpinner(spinner_img); | 53 hideSpinner(spinner_img); |
49 } | 54 } |