Hey there,
I have the following Problem: In a Provider I’m trying to read settings from the ionic Storage (@ionic/storage).
For this I have getter Methods, which return a Promise with the Datatype of the Setting.
I have the following example Code for the getter Method:
public getGpsActive():Promise<boolean>{
return new Promise((reject, resolve) => {
if(this.gpsActive == null){ //Load Value if not loaded previously
this.storage.get('GpsActive').then(data => {
this.gpsActive = data;
if(this.gpsActive == null) {reject(false);} //Reject, if there is no Value in the Storage
else {resolve(this.gpsActive);} //If Value was Successfully Loady, resolve
});
}
else{
resolve(this.gpsActive); //Resolve if Value was previously Loaded
}
});
}
My Problem is, that whenever I call the Method, it goes into the Catch Block as if the Promise was Rejected, except that it returns the right value.
This also happens when I use a getter Method with the Datatype number. On the Other Hand, with string it works.
This is the Code I use, to set Default Values, when no Value was previously set. But it always end in the Catch Block.
this.getGpsActive().catch(error => {
console.log("Defaulting GPS Active");
this.setGpsActive(true);
});
Is this a bug, or am I doing something wrong?
Sincerely,
Justus