More descriptive error codes

suggest change

If geolocation fails, the error callback receives a GeolocationPositionError (the older name was PositionError). code is 1, 2, or 3. Those values also exist as PERMISSION_DENIED, POSITION_UNAVAILABLE, and TIMEOUT on the error object. Pass that object to getErrorCode. Passing only the number does not work, because the function reads err.code and err.PERMISSION_DENIED.

const getErrorCode = function(err) {
  switch (err.code) {
    case err.PERMISSION_DENIED:
      return "PERMISSION_DENIED";
    case err.POSITION_UNAVAILABLE:
      return "POSITION_UNAVAILABLE";
    case err.TIMEOUT:
      return "TIMEOUT";
    default:
      return "UNKNOWN_ERROR";
  }
};

It can be used in geolocationFailure() like so:

const geolocationFailure = function(err) {
  console.log("ERROR (" + getErrorCode(err) + "): " + err.message);
};

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents