Commits

Andreas Knecht  committed e3ae30a

Better error handling.

  • Participants
  • Parent commits 092cedd

Comments (0)

Files changed (2)

File examples/login/app.js

 
 // Use the AtlassianCrowdStrategy within Passport.
 //   Strategies in passport require a `verify` function, which accept
-//   credentials (in this case, a username and password), and invoke a callback
+//   credentials (in this case a crowd user profile), and invoke a callback
 //   with a user object.  In the real world, this would query a database;
 //   however, in this example we are using a baked-in set of users.
 passport.use(new AtlassianCrowdStrategy({
 //
 //   curl -v -d "username=bob&password=secret" http://127.0.0.1:3000/login
 app.post('/login',
-    passport.authenticate('atlassian-crowd', { failureRedirect:'/login'}),
+    passport.authenticate('atlassian-crowd', { failureRedirect:'/login', failureFlash:"Invalid username or password."}),
     function (req, res) {
         res.redirect('/');
     });

File lib/passport-atlassian-crowd/strategy.js

 
             if (self._retrieveGroupMemberships) {
                 var groupResult = "";
-                http_library.get({
+                var groupRequest = http_library.get({
                     host:parsedUrl.hostname,
                     port:parsedUrl.port,
                     path:parsedUrl.pathname + "/rest/usermanagement/latest/user/group/direct?username=" + username,
                         return self._verify(userprofile, verified);
                     });
                 });
+                groupRequest.on('error', function(err) {
+                    self.error(new Error("Error connecting to Crowd Server '" + self._crowdServer + "': " + err));
+                });
             } else {
                 return self._verify(userprofile, verified);
             }
         });
     });
     crowdRequest.write(postData);
+    crowdRequest.on('error', function(err) {
+        self.error(new Error("Error connecting to Crowd Server '" + self._crowdServer + "': " + err));
+    });
     crowdRequest.end();
 
     function lookup(obj, field) {