Hey guys, we are running into issues when handling plugins on native devices.
For example the Geolocation.getCurrentLocation() function returns a different error object on web than it does on native devices.
The error object on this particular function on native devices currently only holds a message property. Without any documentation, it is hard to see what kind of errors it may throw and to write code around handling these errors.
The error object on web is the GeolocationPositionError. It's a lot easier to write different methods around the types of errors it can throw.
The same goes for other plugins like the Camera plugin.
The preferred solution would be a single error object that we can use to handle the error in the same way across platforms. It would also help to have documentation of the errors that certain functions throw. I currently have to search for the error types in the @capacitor/core package.
javascript errors can have a code number and a few other properties, so this could be done
Adding the needs discussion label
It is difficult to categorise Filesystem errors across different platforms, for example:
try {
await Filesystem.stat({ directory, path })
} catch (err) {
const androidFileNotFound = err.message === 'File does not exist'
const iosFileNotFound = err.message.includes('was not found')
if (androidFileNotFound || iosFileNotFound) {
return null
} else {
// unknown error
throw err
}
}
Perhaps well documented err.code properties could be implemented?
Any updates on this issue? @jcesarmobile
IMO this will be a great improvement.
It is difficult to categorise
Filesystemerrors across different platforms, for example:try { await Filesystem.stat({ directory, path }) } catch (err) { const androidFileNotFound = err.message === 'File does not exist' const iosFileNotFound = err.message.includes('was not found') if (androidFileNotFound || iosFileNotFound) { return null } else { // unknown error throw err } }Perhaps well documented
err.codeproperties could be implemented?
I'd like to see a general error for a file not found scenario as well as the actual platform specific error. Some people might want to handle platform specific errors after all.
One thing that would really help is just documentation around the errors object it throws and the possible messages you can get. I have no idea what kind of error scenarios I can expect and how to handle them properly without going through the source code.
Most helpful comment
It is difficult to categorise
Filesystemerrors across different platforms, for example:Perhaps well documented
err.codeproperties could be implemented?