Skip to content

Commit

Permalink
fix location error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpatrick committed Oct 23, 2023
1 parent 23443af commit 67ec189
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ interface PositionOptionOverrides {
desiredAccuracy?: string;
}

// https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError
const PERMISSION_ERROR_MESSAGES: any = {
1: 'Permission denied.',
2: 'Position unavailable.',
3: 'Timeout.',
};

const DEFAULT_POSITION_OPTIONS: PositionOptions = {
maximumAge: 0,
timeout: 1000 * 30, // 30 seconds
Expand Down Expand Up @@ -95,9 +88,8 @@ class Navigator {
return resolve({ latitude, longitude, accuracy });
},
(err: GeolocationPositionError) => { // location call failed or user did not grant permission
if (err && err.code) {
const message = PERMISSION_ERROR_MESSAGES[err.code.toString()] || 'unknown';
return reject(new RadarLocationPermissionsError(message));
if (err && err.code === 1) {
return reject(new RadarLocationPermissionsError('Permission denied.'));
}
return reject(new RadarLocationError('Could not determine location.'));
},
Expand Down

0 comments on commit 67ec189

Please sign in to comment.