From 3d20ec6542517831c29b16d20025d6a79f69d1a6 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Mon, 14 Nov 2011 14:28:05 -0700
Subject: [PATCH] fix a missing non-object json response - issue #217

---
 bin/browserid                      | 2 +-
 lib/wsapi.js                       | 1 -
 lib/wsapi/email_addition_status.js | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/bin/browserid b/bin/browserid
index a337f3db0..55aa2a8ba 100755
--- a/bin/browserid
+++ b/bin/browserid
@@ -137,7 +137,7 @@ app.use(function(req, resp, next) {
   resp.json = function(obj) {
     if (!obj || typeof obj !== 'object') {
       logger.error("INTERNAL ERROR!  *all* json responses must be objects");
-      throw "internal error";
+      return httputils.serverError(resp, "broken internal API implementation");
     }
     realRespJSON.call(resp, obj);
   };
diff --git a/lib/wsapi.js b/lib/wsapi.js
index 7eb2ac33c..38838543e 100644
--- a/lib/wsapi.js
+++ b/lib/wsapi.js
@@ -245,7 +245,6 @@ exports.setup = function(options, app) {
         wsapis[operation].validate = function(req,res,next) { next(); };
       }
 
-
     } catch(e) {
       var msg = "error registering " + operation + " api: " + e;
       logger.error(msg);
diff --git a/lib/wsapi/email_addition_status.js b/lib/wsapi/email_addition_status.js
index dc7ef61bb..87d387cdb 100644
--- a/lib/wsapi/email_addition_status.js
+++ b/lib/wsapi/email_addition_status.js
@@ -25,7 +25,7 @@ exports.process = function(req, res) {
         delete req.session.pendingAddition;
         res.json({ status: 'complete' });
       } else if (!req.session.pendingAddition) {
-        res.json('failed');
+        res.json({ status: 'failed' });
       } else {
         db.emailForVerificationSecret(req.session.pendingAddition, function (email) {
           if (email) {
-- 
GitLab