From cef5b005ac0a4159be0e78f8fe18d7098f582feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Ranum?= Date: Fri, 9 Sep 2016 16:25:39 +0200 Subject: [PATCH] feat(checkin): incl validation errors in response These are the errors returned from the model and will not map direcly with the JSON sent to the API. --- index.js | 8 +++++--- test/acceptance/checkin.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 9c20175..43917e0 100644 --- a/index.js +++ b/index.js @@ -116,10 +116,12 @@ router.post('/steder/:sted/besok', requireAuth, getNtbObject, (req, res, next) = }); promise.catch(error => { - // @TODO better error message exists in error.errors - if (error.name === 'ValidationError') { - next(new HttpError(error.message, 400, error)); + res.status(400).json({ + message: 'Checkin validation failed', + code: 400, + errors: error.errors, + }); } else { next(new HttpError('Database connection failed', 500, error)); } diff --git a/test/acceptance/checkin.js b/test/acceptance/checkin.js index 4f03560..dafe708 100644 --- a/test/acceptance/checkin.js +++ b/test/acceptance/checkin.js @@ -77,9 +77,11 @@ describe('POST /steder/:sted/besok', () => { .set('X-User-Token', 'abc123') .send({ lon: 1337, lat: 4444 }) .expect(400) - .expect({ - code: 400, - message: 'Checkin validation failed', + .expect(res => { + assert.equal(res.body.code, 400); + assert.equal(res.body.message, 'Checkin validation failed'); + assert.equal(typeof res.body.errors['location.coordinates.0'], 'object'); + assert.equal(typeof res.body.errors['location.coordinates.1'], 'object'); }) ));