Error Handler Custom Login Form

How do I distinguish what error I am getting with a custom login form? An example the user does not exist in the list of users.

function login(e) {
        var button = this;
        var username = document.getElementById('email').value;
        var password = document.getElementById('password').value;
        button.disabled = true;
          realm: databaseConnection,
          username: username,
          password: password,
          captcha: captcha.getValue()
        }, function(err) {
          if (err) displayError(err);
          button.disabled = false;