0
Вот функция geolocate()
, которая асинхронно вызывает службу геолокации в React Native.Исключение распространения в Реагенте Native
Проблема заключается в том, что после ошибки, вызванной внутри geolocationError()
, она не распространяется на родителя geolocate()
, но красный экран ошибки появляется незамедлительно.
Как распространять ошибку на catch()
блок geolocate()
?
async geolocate() {
try {
let result = await navigator.geolocation.getCurrentPosition(
this.geolocationSuccess.bind(this),
this.geolocationError.bind(this),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
if (result != null) return result;
} catch(err) {
// This doesn't get called
Alert.alert(
"Location unknown",
"Turn localization services on.",
[
{text: 'OK', onPress:() => console.log('OK')},
]
);
};
}
geolocationError(err) {
console.log(err);
throw err; // Stops here -> Promise.reject() does better job here, but still results in "Unhandled promise rejection"
}