diff --git a/lib/load_gen/common.js b/lib/load_gen/common.js index f26a4dfbc354a55aa1eb5bf18fcdd55c3f29ba56..619b989dd7b274dc0414f0bc5d37567d97c13205 100644 --- a/lib/load_gen/common.js +++ b/lib/load_gen/common.js @@ -13,9 +13,13 @@ exports.auth = function(cfg, user, ctx, email, cb) { cfg, '/wsapi/authenticate_user', ctx, { email: email, pass: user.password }, function(r) { - if (JSON.parse(r.body).success !== true) return cb("failed to authenticate"); - ctx.session.authenticated = true; - cb(); + try { + if (JSON.parse(r.body).success !== true) throw "non-success response " + r.code + (r.body ? (" - " + r.body) : ""); + ctx.session.authenticated = true; + cb(); + } catch (e) { + cb('failed to authenticate: ' + e); + } } ); } @@ -32,9 +36,14 @@ exports.authAndKey = function(cfg, user, ctx, email, cb) { email: email, pubkey: keypair.publicKey.serialize() }, function(resp) { - if (typeof resp.body !== 'string') return cb("can't certify key"); - userdb.addCertToUserCtx(ctx, email, resp.body); - cb(); + try { + if (resp.code !== 200) throw "non-200 status: " + resp.code; + if (typeof resp.body !== 'string') throw cb("no response body"); + userdb.addCertToUserCtx(ctx, email, resp.body); + cb(); + } catch(e) { + cb("can't certify key" + (e ? (": " + e.toString()) : "")); + } }); } }; @@ -73,9 +82,10 @@ exports.genAssertionAndVerify = function(cfg, user, ctx, email, audience, cb) { assertion: assertion }, function (r) { try { + if (r.code !== 200) throw "non-200 status: " + resp.code; cb(JSON.parse(r.body).status === 'okay' ? undefined : "verification failed"); } catch(e) { - return cb("response body: " + r.body + " error: " + e.toString()); + return cb("can't verify: " + e.toString()); } }); });