From 97992764729619a1ea721e0f3224594108eb433d Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 5 Dec 2012 11:25:01 -0500 Subject: [PATCH] Present errors, namespace events. --- js/id/connection.js | 9 ++++----- js/id/oauth.js | 6 +++--- js/lib/d3.typeahead.js | 6 +++--- js/lib/ohauth.js | 11 +++++++++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/js/id/connection.js b/js/id/connection.js index 432c052ab..629122f86 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -107,18 +107,17 @@ iD.Connection = function() { path: '/api/0.6/changeset/create', options: { header: { 'Content-Type': 'text/xml' } }, content: iD.format.XML.changeset(comment) - }, - function (changeset_id) { + }, function (err, changeset_id) { oauth.xhr({ method: 'POST', path: '/api/0.6/changeset/' + changeset_id + '/upload', options: { header: { 'Content-Type': 'text/xml' } }, content: iD.format.XML.osmChange(user.id, changeset_id, changes) - }, function () { + }, function (err) { oauth.xhr({ method: 'PUT', path: '/api/0.6/changeset/' + changeset_id + '/close' - }, function () { + }, function (err) { callback(changeset_id); }); }); @@ -126,7 +125,7 @@ iD.Connection = function() { } function userDetails(callback) { - oauth.xhr({ method: 'GET', path: '/api/0.6/user/details' }, function(user_details) { + oauth.xhr({ method: 'GET', path: '/api/0.6/user/details' }, function(err, user_details) { var u = user_details.getElementsByTagName('user')[0]; callback(connection.user({ display_name: u.attributes.display_name.nodeValue, diff --git a/js/id/oauth.js b/js/id/oauth.js index b613b30cd..cdf2dcb3a 100644 --- a/js/id/oauth.js +++ b/js/id/oauth.js @@ -49,9 +49,9 @@ iD.OAuth = function() { var oauth_token_secret = token('oauth_token_secret'); o.oauth_signature = ohauth.signature(oauth_secret, oauth_token_secret, ohauth.baseString(options.method, url, o)); - ohauth.xhr(options.method, url, o, options.content, options.options, function(xhr) { - if (xhr.responseXML) callback(xhr.responseXML); - else callback(xhr.response); + ohauth.xhr(options.method, url, o, options.content, options.options, function(err, xhr) { + if (xhr.responseXML) callback(err, xhr.responseXML); + else callback(err, xhr.response); }); }; diff --git a/js/lib/d3.typeahead.js b/js/lib/d3.typeahead.js index 689b30925..ac200d0be 100644 --- a/js/lib/d3.typeahead.js +++ b/js/lib/d3.typeahead.js @@ -13,7 +13,7 @@ d3.typeahead = function() { top: rect.bottom + 'px' }); selection - .on('keyup.update', update); + .on('keyup.typeahead', update); hidden = false; } @@ -26,8 +26,8 @@ d3.typeahead = function() { } selection - .on('focus', setup) - .on('blur', hide); + .on('focus.typeahead', setup) + .on('blur.typeahead', hide); var idx = 0; function update() { diff --git a/js/lib/ohauth.js b/js/lib/ohauth.js index f72dc01f3..f447e9cdc 100644 --- a/js/lib/ohauth.js +++ b/js/lib/ohauth.js @@ -19,9 +19,16 @@ ohauth.stringQs = function(str) { }; ohauth.xhr = function(method, url, auth, data, options, callback) { - var xhr = new XMLHttpRequest(); + var xhr = new XMLHttpRequest(), + twoHundred = /^20\d$/; xhr.onreadystatechange = function() { - if (4 == xhr.readyState && 0 !== xhr.status) callback(xhr); + if (4 == xhr.readyState && 0 !== xhr.status) { + if (twoHundred.test(xhr.status)) { + callback(null, xhr); + } else { + callback(xhr, null); + } + } }; var headers = (options && options.header) || { 'Content-Type': 'application/x-www-form-urlencoded' }; xhr.open(method, url, true);