Best way to catch and differentiate errors in a realm function

Yes I’m experiencing the same issue. Basically, my solution is:

Whenever I want to indicate an error to the client that is the result of the developer doing something wrong (i.e., not calling the function correctly or not properly validating user input before calling the function), I simply throw an error and expect the client app to just print the error in the console to inform the developer of their mistake.

However, if I want the function to indicate error information that will ultimately be conveyed to the user, I return those errors through a field in the returned document instead, so that I can be super precise about the cause of the error.

If MongoDB or anyone else has a better solution to this issue, please let me know!