Jump to content

HTML GEOLOCATION API - HANDLING ERRORS QUESTION


noetherian

Recommended Posts

Hello,

A question about this code: 

function showError(error) {
  switch(error.code) {
    case error.PERMISSION_DENIED:
      x.innerHTML = "User denied the request for Geolocation."
      break;
    case error.POSITION_UNAVAILABLE:
      x.innerHTML = "Location information is unavailable."
      break;
    case error.TIMEOUT:
      x.innerHTML = "The request to get user location timed out."
      break;
    case error.UNKNOWN_ERROR:
      x.innerHTML = "An unknown error occurred."
      break;
  }
}

According to the Geolocation spec. , there are 3 constants representing errors:

PERMISSION_DENIED,  POSITION_UNAVAILABLE, and TIMEOUT. It doesn't mention UNKNOWN_ERROR

So I don't understand how the case of error.UNKNOWN_ERROR fits in the code.

Was it predefined anywhere else? what will it return? and how can I cause an (intentional) unknown error to trigger this case?

Thank you very much for any assistance. 

Link to comment
Share on other sites

I think I got it. 

By just removing the first three breaks, I triggered the unknown error case and could see the result.

So to answer my own questions:

Was it predefined anywhere else? No, and also I understand that it didn't need to be.

What will it return?   error.UNKNOWN_ERROR simply returns 'undefined' and it's not a problem at all.

How can I cause an (intentional) unknown error to trigger this case?   I didn't need to cause a specific run-time unknown error to trigger the last case ,

I just removed the first three breaks and the last case was triggered, so I could see that error.UNKNOWN_ERROR  returns 'undefined' and realize that it is just fine.

"An unknown error occurred" message is printed on the page as it should be. 

Thanks!

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...