How can I catch the geolocation specific error to notify the user that they must have geolocation turned on?
The catch logs an error called PositionError as referenced here in the Mozilla docs "https://developer.mozilla.org/en-US/docs/Web/API/PositionError".
*Note: my code does not catch the error, it simply displays:
Uncaught (in promise) ReferenceError: PositionError is not defined
Code
getCurrentLocation() {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject, {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
});
});
},
async inout() {
try {
let location = await this.getCurrentLocation();
let response = await axios.post(API.URL, {});
} catch (e) {
if(e instanceof PositionError) {
console.log('position error')
}
}
}
Object.prototype.toString.call(error) === '[object PositionError]'
. – Hesslerasync/await
is part of ES2017, not ES7. – Tetragram