11import { getCurrentPositionAsync , PermissionStatus , requestForegroundPermissionsAsync } from 'expo-location' ;
22import type { PermissionResponse } from 'expo-location' ;
3- import { Platform } from 'react-native' ;
43import { GeolocationErrorCode } from './getCurrentPosition.types' ;
54import type { GetCurrentPosition } from './getCurrentPosition.types' ;
5+ import getGeolocationError from './getGeolocationError' ;
66
77const getCurrentPosition : GetCurrentPosition = async ( success , error , options ) => {
88 const foregroundPermissionResponse : PermissionResponse = await requestForegroundPermissionsAsync ( ) ;
@@ -16,19 +16,8 @@ const getCurrentPosition: GetCurrentPosition = async (success, error, options) =
1616 const currentPosition = await getCurrentPositionAsync ( options ) ;
1717 success ( currentPosition ) ;
1818 } catch ( caughtError ) {
19- let message = 'Geolocation call failed' ;
20- let code = GeolocationErrorCode . POSITION_UNAVAILABLE ;
21-
22- if ( Platform . OS === 'web' && caughtError instanceof GeolocationPositionError ) {
23- code = caughtError . code ;
24- message = caughtError . message ;
25- } else if ( caughtError instanceof Error ) {
26- message = caughtError . message ;
27- } else if ( typeof caughtError === 'string' ) {
28- message = caughtError ;
29- }
30-
31- error ( { code, message} ) ;
19+ const geolocationError = getGeolocationError ( caughtError ) ;
20+ error ( geolocationError ) ;
3221 }
3322} ;
3423
0 commit comments