tobiaswaltl opened a new issue #693:
URL: https://github.com/apache/cordova-plugin-camera/issues/693
# Feature Request
## Motivation Behind Feature
<!-- Why should this feature be implemented? What problem does it solve? -->
If the plugin threw structured errors having an error code and an error
message, developers could handle these errors without relying on magic strings
representing the error message.
For instance, if the camera permission was not granted on Android devices,
the error is currently only '20'. If it was `{ code: '20', message: 'Camera
permission not granted' }` instead, it would be more understandable and the
error handler could differentiate based on the `code`.
## Feature Description
<!--
Describe your feature request in detail
Please provide any code examples or screenshots of what this feature would
look like
Are there any drawbacks? Will this break anything for existing users?
-->
I suggest passing a structured error object to the `onError` handle as
described above. Furthermore, it would be great to export an enum with all the
error codes like
```
export enum Error {
NO_PERMISSION: '20',
USER_CANCELED: '99',
// ...
}
```
This would allow for handling errors like
```
navigator.camera.getPicture(
() => { /* handle success */ },
error => {
switch(error.code) {
case Error.NO_PERMISSION:
// show a popup asking to grant the permission
case Error.USER_CANCELED:
// do nothing as the user chose to cancel the action
...
}
},
cameraOptions,
);
```
This would break existing error handlers comparing with the message.
## Alternatives or Workarounds
<!--
Describe alternatives or workarounds you are currently using
Are there ways to do this with existing functionality?
-->
Currently, error handling is only possible via comparing the error string
with magic strings (i.e. the actual messages).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]