realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
968 stars 61 forks source link

Expose error codes in the different realm exceptions #1419

Open clementetb opened 1 year ago

clementetb commented 1 year ago

Problem

The user has no access to the error code property in app exceptions, if they like to react to a specific error code they have to do string matching.

Solution

Expose the error code as a public property.

Alternatives

No response

How important is this improvement for you?

Would be a major improvement

Feature would mainly be used with

Atlas Device Sync

cmelchior commented 1 year ago

We tried to solve this through the Exception type hierarchy. This could point to us needing to extend this hierarchy.

What was the exact use case that caused this?

clementetb commented 1 year ago

I was trying to automatically register a user when logging in. The thing is that I tried to register and then log in, doing it the other way around (logging in and then registering) solves the issue because we have an exception to catch when a user does not exist. So there is no need to extend the hierarchy.

cmelchior commented 1 year ago

After discussion, we need to verify this check actually works:

                ErrorCode.RLM_ERR_ACCOUNT_NAME_IN_USE -> {
                    UserAlreadyExistsException(msg)
                }