From cb362b581be11679bab58ceec5bdc69af59daed6 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Thu, 11 Feb 2016 23:36:55 -0500 Subject: [PATCH] fix(bins): update har-validator to promise version --- lib/routes/bins/create.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/routes/bins/create.js b/lib/routes/bins/create.js index 01a75d8b..b4d841fd 100644 --- a/lib/routes/bins/create.js +++ b/lib/routes/bins/create.js @@ -43,22 +43,21 @@ module.exports = function (req, res, next) { mock.content.size = 0 - validate.response(mock, function (err, valid) { - if (!valid) { - res.body = { - errors: err.errors - } - - return next() - } + validate.response(mock) + .then(function () { + var id = uuid.v4() - var id = uuid.v4() + this.client.set('bin:' + id, JSON.stringify(mock)) - this.client.set('bin:' + id, JSON.stringify(mock)) + res.view = 'redirect' + res.status(201).location(util.format('/bin/%s', id)).body = id + }.bind(this)) - res.view = 'redirect' - res.status(201).location(util.format('/bin/%s', id)).body = id + .catch(function (err) { + res.body = { + errors: err.errors + } + }) - next() - }.bind(this)) + .then(next) }