ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.06k forks source link

checkFile error on non-existent file #1417

Open sertal70 opened 7 years ago

sertal70 commented 7 years ago

A call to File.checkFile() on a non-existent file results in a callback error with code NOT_FOUND_ERR. The function specification of checkFile() says:

Returns a Promise that resolves with a boolean or rejects with an error.

Even if it is not further clarified in the specification, is almost intuitive expecting that it should return a Promise "false" if the file doesn't exist, instead of a reject with the NOT_FOUND_ERR code.

IMHO the function should rejects on error conditions only, for example on a non-existent path, etc. The non-existence of the file being checked is not an error but one of the possibles results of the function.

Thanks!

sertal70 commented 7 years ago

any chances having someone looking at this?

pooja-gaikwad15 commented 6 years ago

Any ideas? have the same issue..

polymoses commented 6 years ago

This is misleading and should be fixed, or at least clarified in the documentation. Thanks.

mparpaillon commented 6 years ago

Since nobody seems to care about this issue, I've created this (dirty) wrapper...

fileExists(path, file) {
  return new Promise((resolve, reject) => {
    this.file.checkFile(path, file)
    .then(() => resolve(true))
    .catch(err => err.message === 'NOT_FOUND_ERR' ? resolve(false) : reject(err));
  });
}

It returns a Promise