Add error handling to location detection