Turn the tokenat() function to Javascript OR another way to catch an error from Mongodb Realm?

0 favourites
  • 2 posts
From the Asset Store
7 Errors
$15 USD
7 Errors is a game where you have to find the 7 mistakes before time runs out. Can you find all 7? Have fun looking.
  • Hey there!

    I use the Mongodb Realm Web SDK in my project. When the user inserts wrong login data and presses login there will be an error message in the chrome developer log.

    But how can I get the error code in my app?

    async function loginEmailPassword(email, password) {
     const credentials = Realm.Credentials.emailPassword(email, password);
     try {
     const user = await app.logIn(credentials);
     console.assert(user.id === app.currentUser.id)
     return user;
     } catch(err) {
     console.error("Failed to log in.", err);
     }
    }
    

    This is from the Mongodb documentation but it just won't log the error nor an error code. Nothing.

    I found this and one of the answers included this but I don't understand it.

    Please can someone with more programming knowledge than me explain to me how I can get the error codes from Realm so that I can tell the user why login didn't work?

    Thank you very much!

    Edit:

    I found out that the second of the error codes indeed is from the console.error command. Now I just need to extract the actual error message and code.

    How can I turn the built in tokenat(text, index, separator) function into an actual Javascript function for the importForEvents.js scripts?

    That's what I have so far:

    function tokenat(text, index, separator) {
    	var result = text.substring(text.indexOf(separator) + 1);
    	return result;
    }

    But I'm too dumb to implement the index part for the case if there are multiple separators.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I just found the answer very well hidden in the mongodb forums. The second reply.

    Just copy the function to importsForEvents.js and call it from catch(err) and pass err to it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)