Promise always catches when resolving with boolean or number

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'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

				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");

Is this a bug, or am I doing something wrong?


You have resolve and reject in the wrong order.

Should be:
return new Promise((resolve, reject) => {

1 Like

That fixed it! Thank you so much! I have been stuck with this for days…

Just out of curiosity, wouldn’t this be more efficient from a Promise perspective?