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

Throw error codes instead of message strings in the exception #697

Open
wm-eisos opened this issue Oct 18, 2024 · 2 comments
Open

Throw error codes instead of message strings in the exception #697

wm-eisos opened this issue Oct 18, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@wm-eisos
Copy link

wm-eisos commented Oct 18, 2024

Is your feature request related to a problem? Please describe.
So far the current exceptions thrown have string based messages which is sometimes event differenet between the platforms, whiuch would make it hard to interpret the resulting issue. such as in

self.reject(initializeKey, "BLE permission denied")
for iOS and for Android which basically are permession denials however they are different strings which means the parser on the app side would need to take care about bopth scenarios and this owuld be way easier if it was error codes and would prevent the issue of someone changing the string inside the library causing the parser on the appp end to fail

Describe the solution you'd like
Have error codes instead of string based exceptions so that the user can interpret the values of the error codes way easier than whole strings.

@wm-eisos wm-eisos added the enhancement New feature or request label Oct 18, 2024
@pwespi
Copy link
Member

pwespi commented Oct 20, 2024

Thank you for this feature request. It's a good idea.

The reject method of PluginCall actually supports adding an error code (as string) in addition to an error message, so this could be implemented in a non-breaking way.

Android:
https://github.com/ionic-team/capacitor/blob/cb325a32501118a6ac77071341e1a40f47300866/android/capacitor/src/main/java/com/getcapacitor/PluginCall.java#L74-L75

iOS:
https://github.com/ionic-team/capacitor/blob/cb325a32501118a6ac77071341e1a40f47300866/ios/Capacitor/Capacitor/CAPPluginCall.swift#L45-L46

Would you be able to prepare a PR for this?

@wm-eisos
Copy link
Author

Hey,

Unfortuanatly im not that expecrienced in capacitor plugnis, i believe it would take me longer to implement it. As well as the face that i dont have a MacOS device whiche means iOS development is not possible for me.

However i would also mention that if there is an enum mapping the errors to states it would be nice as i currently saw that the error code as a string.

Best Regards
Wajdi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants