From ed032be98f1193a96540d9c5aa6415418c159d38 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 7 Jan 2013 17:51:50 -0500 Subject: [PATCH] Detect, pass, and display errors. Fixes #124 --- js/id/id.js | 30 +++++++++++++++++++----------- js/id/oauth.js | 5 +++-- js/id/ui/confirm.js | 5 +++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/js/id/id.js b/js/id/id.js index 2ce3f3001..cdd8260d6 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -122,17 +122,25 @@ window.iD = function(container) { l.remove(); history.reset(); map.flush().redraw(); - var modal = iD.modal(); - modal.select('.content') - .classed('success-modal', true) - .datum({ - id: changeset_id, - comment: e.comment - }) - .call(iD.success() - .on('cancel', function() { - modal.remove(); - })); + if (err) { + var desc = iD.confirm() + .select('.description'); + desc.append('h2') + .text('An error occurred while trying to save'); + desc.append('p').text(err.responseText); + } else { + var modal = iD.modal(); + modal.select('.content') + .classed('success-modal', true) + .datum({ + id: changeset_id, + comment: e.comment + }) + .call(iD.success() + .on('cancel', function() { + modal.remove(); + })); + } }); } var changes = history.changes(); diff --git a/js/id/oauth.js b/js/id/oauth.js index c310004e5..2ae0d9c0c 100644 --- a/js/id/oauth.js +++ b/js/id/oauth.js @@ -49,8 +49,9 @@ iD.OAuth = function() { 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(err, xhr) { - if (xhr.responseXML) callback(err, xhr.responseXML); - else callback(err, xhr.response); + if (err) return callback(err); + if (xhr.responseXML) return callback(err, xhr.responseXML); + else return callback(err, xhr.response); }); }; diff --git a/js/id/ui/confirm.js b/js/id/ui/confirm.js index 40558804d..84a8d6c87 100644 --- a/js/id/ui/confirm.js +++ b/js/id/ui/confirm.js @@ -1,9 +1,10 @@ -iD.confirm = function(message) { +iD.confirm = function() { var modal = iD.modal(); modal.select('.modal').classed('modal-alert', true); modal.select('.content') .classed('modal-section', true) - .append('div').attr('class', 'description'); + .append('div') + .attr('class', 'description'); var nochanges = modal.select('.content') .append('button') .attr('class','wide action centered')