Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Added method to handle unauthorised requests
Browse files Browse the repository at this point in the history
Disable searching and allow manual entry
  • Loading branch information
jbate committed Oct 30, 2015
1 parent 9d12e2b commit 667e6df
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
22 changes: 20 additions & 2 deletions dist/js/contact-data-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ ContactDataServices.address = function(options){
if(event){
event.preventDefault();
}
// Enable searching
instance.enabled = true;
// Hide formatted address
instance.result.hide();
// Show search input
Expand All @@ -640,6 +642,22 @@ ContactDataServices.address = function(options){
instance.events.trigger("post-reset");
};

// How to handle unauthorised (invalid token?) requests
instance.unauthorised = function(){
instance.enabled = false;

// As searching is disabled, show button to render final address instead
var button = document.createElement("button");
button.innerText = "Submit";
instance.input.parentNode.insertBefore(button, instance.input.nextSibling);
button.addEventListener("click", function(){
// Simulate a manual "use address entered" entry
instance.picklist.useAddressEntered.click();
// Remove the button
instance.input.parentNode.removeChild(button);
});
};

// Use this to initiate and track XMLHttpRequests
instance.request = {
currentRequest: null,
Expand All @@ -658,9 +676,9 @@ ContactDataServices.address = function(options){
// We reached our target server, but it returned an error
instance.searchSpinner.hide();

// If the request is unauthorized we should probably disable future requests
// If the request is unauthorized (invalid token) we should probably disable future requests
if(instance.request.currentRequest.status === 401){
instance.enabled = false;
instance.unauthorised();
}
}
};
Expand Down
Loading

0 comments on commit 667e6df

Please sign in to comment.