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

Methods should return always a Promise, also when Cordova or the plugin is not available #294

Closed
Ritzlgrmft opened this issue Jul 14, 2016 · 6 comments · Fixed by #304
Closed

Comments

@Ritzlgrmft
Copy link
Contributor

Par example, look at the method

static getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition> { return; }

It declares to return always a Promise object. But that is not true. If either Cordova or the plugin is not available, just an object with a property named error is returned.

I would prefer, that ionic-native returns in such a case just a rejected Promise. That would make my coding much easier.

With the current implementation, I have to check if the returned value is really a Promise. Only then I can use methods like then() on it. Otherwise I would get unexpected errors at least while testing in the browser.

@mlynch
Copy link
Collaborator

mlynch commented Jul 14, 2016

Good call, we should do this (surprised we didn't do that from the start...)

ihadeed added a commit that referenced this issue Jul 14, 2016
@ihadeed
Copy link
Collaborator

ihadeed commented Jul 14, 2016

This should do the trick: a1f47a7

@ihadeed
Copy link
Collaborator

ihadeed commented Jul 14, 2016

@Ritzlgrmft I just checked, in case of an error it still returns a promise that rejects with the error message plugin_not_installed or cordova_not_available ..

Can you provide steps to reproduce a case where it returns back an object instead of a promise?

Thanks

@Ritzlgrmft
Copy link
Contributor Author

I created a new Ionic project with ionic start ... --v2 --typescript, updated ionic-native to the newest version and added to platform.ready:

try {
  IBeacon.enableDebugLogs()
    .then(() => { 
      alert('success'); 
    }).catch(reason => { 
      alert('failed: ' + reason); 
    });
} catch (e) { 
  alert('error: ' + e); 
}

Maybe this happens because of the sync option?

@ihadeed
Copy link
Collaborator

ihadeed commented Jul 15, 2016

Yes it's because of the sync option.

The IBeacon plugin is kinda a special case ... the original plugin itself returns the promise, not ionic-native. So we can't really play with that, unless if we implement your suggestion in #241 which will require modifying the plugin and plugin.ts.

@ihadeed
Copy link
Collaborator

ihadeed commented Jul 15, 2016

FYI: #304

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