bjorn2404 / jQuery-Store-Locator-Plugin

A store locator plugin using Google Maps API version 3
MIT License
495 stars 235 forks source link

Error handling #38

Closed bhardy closed 9 years ago

bhardy commented 9 years ago

There appears to be an error with your error alerts. If you go to your demo and type in an invalid zip or postal you get a console error: Safari: TypeError: undefined is not an object (evaluating ‘_this.settings.geocodeErrorAlert’) Chrome: Uncaught TypeError: Cannot read property ‘addressErrorAlert’ of undefined I need to implement error handling and this is holding me back. I’m changing your plugin code for our implementation but you may want to fix it.

bjorn2404 commented 9 years ago

Thanks. Fixed in v2.0.4

bhardy commented 9 years ago

_this.notify(_this.settings.geocodeErrorAlert + status); is appending .ZERO_RESULTS to the error messages. I've removed + status and it appears fine, although I'm not thoroughly testing.

bhardy commented 9 years ago

Also, calling the callbackFunction(null); after it just displays 'Unable to find address' which seems redundant. It also makes error handling difficult because it runs the callback twice. The first instance of the callback reports the error and the second says unable to find. I'm injecting code onto the page like so:

var cb_error = function(error_message_string) {
  $('#bh-sl-address').css('border-color', '#cc4c3f');
  $('#bh-sl-user-location').append('<span class="map-error">'+error_message_string+'</span>');
}

Because the callback is called multiple times I end up with two instances of <span class="map-error">. I can't add $('.map-error').remove(); to the beginning of the function because then the second callback simply removes the first error (leaving the user with just: Unable to find address). If the user does multiple erroneous searches (or just clicks search again) the errors begin to pile up.

I hope that made sense. Long story short I've just commented out callbackFunction(null); and it's working for my purposes.