Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geolocation.watchPosition passes errors to the success function #3303

Closed
gnesher opened this issue Jan 29, 2020 · 3 comments
Closed

geolocation.watchPosition passes errors to the success function #3303

gnesher opened this issue Jan 29, 2020 · 3 comments

Comments

@gnesher
Copy link

gnesher commented Jan 29, 2020

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://ionicworldwide.herokuapp.com/

Current behavior:
Using geolocation.watchPosition when (for example) user refuses to provide access to the device location will provide the following error object in the subscription (without throwing an error)

GeolocationPositionError {code: 2, message: "application does not have sufficient geolocation permissions."}code: 2message: "application does not have sufficient geolocation permissions."proto: GeolocationPositionError

The return value is defined as Geoposition (interface) and doesn't allow me to a GeolocationPositionError object.

Expected behavior:
The expected behavior would be to throw the error and close the subscription

Steps to reproduce:
start listening to the geolocation of the device without approving access to the device location

Other information:

Tested only on Android devices

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Ionic:

ionic (Ionic CLI) : 4.12.0 (C:\Users\gnesher\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.11.7
@angular-devkit/build-angular : 0.803.23
@angular-devkit/schematics : 8.2.2
@angular/cli : 8.2.2
@ionic/angular-toolkit : 2.0.0

Cordova:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 15 other plugins)

System:

Android SDK Tools : 26.1.1 (C:\Android\android-sdk)
NodeJS : v12.14.1 (C:\Program Files\nodejs\node.exe)
npm : 6.13.4
OS : Windows 10

@DavidWiesner
Copy link
Contributor

I agree this is a weird behavior. In the specs of (watchPosition)[https://w3c.github.io/geolocation-api/#dfn-watch-process] you can see multiple errors can be fired before a new position will be sended. Observables instead can only handle one Error and will be closed after the first error. Maybe that's the reason the ionic team decide to ship both value to the next callback.

But this behavior should be at least also be expressed in the types. Therefore the return type of watchPostion should be changed to Observable<Geoposition|GeolocationPositionError>

@DavidWiesner
Copy link
Contributor

Sorry i mixed up Observable and Subject. So you are right. The Error should be delivered via the error callback of the Observable

@DavidWiesner
Copy link
Contributor

Sorry my fault I read the Rxjs context about Observables (http://reactivex.io/documentation/contract.html) again. An Observable can only emit on error. But as stated in the w3c Geolocation API Specification an error can be occur multiple times (see https://w3c.github.io/geolocation-api/#dfn-watch-process) e.g.: a timeout. I reopen the pullrequest to adjust the types that will be delivered by the Observable. That will make it more clear waht you can expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants