Skip to content

Commit

Permalink
handle malformed JSON response from verifier gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
lloyd committed Sep 16, 2011
1 parent 58b6ee0 commit 4f0b11c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions server/main.js
Expand Up @@ -79,15 +79,18 @@ app.post("/api/login", function (req, res) {
var body = "";
vres.on('data', function(chunk) { body+=chunk; } )
.on('end', function() {
console.log(body);

var verifierResp = JSON.parse(body);
var valid = verifierResp && verifierResp.status === "okay";
var email = valid ? verifierResp.email : null;

req.session.email = email;

res.json(email);
try {
var verifierResp = JSON.parse(body);
var valid = verifierResp && verifierResp.status === "okay";
var email = valid ? verifierResp.email : null;

req.session.email = email;

res.json(email);
} catch(e) {
// bogus response from verifier! return null
res.json(null);
}
});
});
vreq.setHeader('Content-Type', 'application/x-www-form-urlencoded');
Expand Down

0 comments on commit 4f0b11c

Please sign in to comment.