diff --git a/lib/wsapi_client.js b/lib/wsapi_client.js index 81dbce7e09b56896a9dbdccc027eba02d74dbceb..a71202306d74fade5e5053939159e17b78c0db2b 100644 --- a/lib/wsapi_client.js +++ b/lib/wsapi_client.js @@ -95,7 +95,8 @@ function withCSRF(cfg, context, cb) { exports.get(cfg, '/wsapi/session_context', context, undefined, function(err, r) { if (err) return cb(err); try { - if (r.code !== 200) throw 'http error'; + if (r.code !== 200) + return cb({what: "http error", resp: r}); // report first error context.session = JSON.parse(r.body); context.sessionStartedAt = new Date().getTime(); cb(null, context.session.csrf_token); @@ -109,7 +110,14 @@ function withCSRF(cfg, context, cb) { exports.post = function(cfg, path, context, postArgs, cb) { withCSRF(cfg, context, function(err, csrf) { - if (err) return cb(err); + if (err) { + if (err.what == "http error") { + // let the session_context HTTP return code speak for the overall + // POST + return cb(null, err.resp); + } + return cb(err); + } // parse the server URL (cfg.browserid) var uObj; diff --git a/tests/stalled-mysql-test.js b/tests/stalled-mysql-test.js index 46b529baa6d2ab661e975122016de5a493a8d005..6ebb61eb8269969a5bb6f6e83249378f6222490c 100755 --- a/tests/stalled-mysql-test.js +++ b/tests/stalled-mysql-test.js @@ -79,9 +79,8 @@ suite.addBatch({ suite.addBatch({ "ping": { topic: wsapi.get('/wsapi/ping', {}), - "fails with 500 when db is stalled": function(err, r) { - // address info with a primary address doesn't need db access. - assert.strictEqual(r.code, 500); + "fails with 503 when db is stalled": function(err, r) { + assert.strictEqual(r.code, 503); } }, "address_info": { @@ -216,7 +215,7 @@ suite.addBatch({ "ping": { topic: wsapi.get('/wsapi/ping', { }), "fails": function(err, r) { - assert.strictEqual(r.code, 500); + assert.strictEqual(r.code, 503); } }, @@ -391,15 +390,11 @@ suite.addBatch({ "fails with 404": function(err, r) { assert.strictEqual(r.code, 404); } - } -}); - -// logout doesn't need database, it should still succeed -suite.addBatch({ - "logout": { + }, + "logout": { // logout needs the database too topic: wsapi.post('/wsapi/logout', { }), - "succeeds": function(err, r) { - assert.strictEqual(r.code, 200); + "fails with 503": function(err, r) { + assert.strictEqual(r.code, 503); } } });