changeset 1:0c19fadfc12d

Serve the right error message when the TYPE of the PHOTO is missing.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 31 Mar 2011 00:35:19 +0200
parents d5cfe54f11aa
children ad496e8a5e66
files avatar.js
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/avatar.js
+++ b/avatar.js
@@ -139,9 +139,15 @@ function onIq(stanza) {
 
 	try {
 		var photo = vCard.getChild('PHOTO', 'vcard-temp');
-		var type = photo.getChild('TYPE', 'vcard-temp').getText();
 		var base64 = photo.getChild('BINVAL', 'vcard-temp').getText();
 
+		try {
+			var type = photo.getChild('TYPE', 'vcard-temp').getText();
+		} catch (e) {
+			res.writeHead(500, {'Content-Type': 'text/plain'});
+			res.end('Error: this user’s vCard doesn’t specify the MIME type of its avatar.');
+		}
+
 		var ext;
 		for (var i in extensions)
 			if (type == extensions[i])