How to programatically get error code?

Hi guys Igot this code to login, the problem is that there is no way to know the reason why failed, I need to show info to the UI or know what type of issue I’m facing. Doc doesn’t say anything about errors.

try {
  const user = await realmApp.logIn(credentials);
  console.log('signed in', user);
} catch (e) {

It print out:

Error: Request failed (POST invalid username/password (status 401)
    at Function.fromRequestAndResponse (
    at async Fetcher.fetch (
    at async Fetcher.fetchJSON (
    at async Authenticator.authenticate (
    at async App.logIn (
    at async handleSignIn (SignIn.js:37)

Programmatically I’m expecting an object with error_code Luke I see on the network http payload but I’m not able to retrieve it on realm-web and act to different situations like wrong password/username or email confirmation pending for example.

This is a cross post to a StackOverflow question

It’s a good idea to post questions in one place to focus possible answers.

Yeah. I tried other community because the lack of support in stackoverflow. I don’t think it’s bad.

Not bad at all! If someone has as answer though, better to focus the attention on that answer instead of searching around for it.

@Juan_Jose_N_A This could definitely use improvement. In the web tutorial we parse the info out using a regex but we realize this shouldn’t be necessary. Instead we could throw a custom RealmAuthError that includes the error code and message as separate properties. We have added this to backlog and hope to get to it in the next quarter

I just spoke with @Ian_Ward offline and we actually do support this already in Realm Web.

I’ve created a small CodeSandbox demonstrating how to get the individual properties from the error object:


Is MongoDBRealmError the ‘next generation’ of RealmError where you could compare it with the Enums to handle the error?

See my ‘attempt’ at an answer to the same question on SO - if RealmError is gone then I will delete that as it’s no longer applicable.

I tested and yes it works already on web. Amazing. But it need to be documented now it is just a secret.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.