How could i know all about error codes?

when i request email registerUser api with already existing email address, i’ve got below error response.

{"error":"name already in use","error_code":"AccountNameInUse","link":"https://realm.mongodb.com/groups/60a2045aa392f7796f889452/apps/60a2100d124d3d40ba0e2d6e/logs?co_id=60c0d3bc91934ca3febbe284"}

and then, i’m wondering if i could know all error responses in advance, i think we could develop our code more carefully.

i need your some advice. thank you

Not sure if this is what you’re looking for but here are some links I found with lists of error codes for Realm.

MongoDB realm sync errors

Github list of errors for Realm

1 Like

Hey Aiden, welcome to the forums! :wave:

Unfortunately I don’t think we have documentation on all of the errors you might encounter across all of Realm’s app services. The links that Eli posted only include errors related to Realm Sync so you won’t find anything for the email/password auth error you encountered.

Would something like the Sync Errors page for the other types of errors be useful for you? We’d be happy to add this to the docs though I can’t guarantee a timeline.

In the meantime, hopefully this code (adapted from the web tutorial) covers your needs for email/password auth:

function handleAuthenticationError(err) {
  const handleUnknownError = () => {
    console.warn(
      "Something went wrong with a Realm login or signup request. See the following error for details."
    );
    console.error(err);
  };
  if (err instanceof Realm.MongoDBRealmError) {
    const { error, statusCode } = err;
    const errorType = error || statusCode;
    switch (errorType) {
      case "invalid username":
        // Invalid email address
        break;
      case "invalid username/password":
      case "invalid password":
      case 401:
        // Invalid password
        break;
      case "name already in use":
      case 409:
        // Email is already registered
        break;
      case "password must be between 6 and 128 characters":
      case 400:
        // Invalid password - must be between 6 and 128 characters
        break;
      default:
        // In theory you won't ever hit this default, but if an error message/code without a case ever comes up it will fall back to this.
        handleUnknownError();
        break;
    }
  } else {
    // In this case, the error isn't a MongoDB Realm error so you probably need to add another error handler somewhere else to catch it before it gets passed to this function.
    handleUnknownError();
  }
}
3 Likes

Thanks for the reply :slight_smile:

email/password errors are so awesome answer we wanted, i appreciate it!
and furthermore, if mongo realm provides various error status docs we’d be so happy.
mongo DB, atlas and realm-web are our team’s primary development stack :smiling_face_with_three_hearts:

2 Likes

Glad it helped! I’ll look into getting some new error docs scheduled for work soon.

3 Likes