Skip to content

Commit

Permalink
Merge pull request #48 from Turistforeningen/feat/validation-errors-i…
Browse files Browse the repository at this point in the history
…n-response

feat(checkin): incl validation errors in response
  • Loading branch information
Håvard Ranum authored Sep 9, 2016
2 parents 886bb8e + cef5b00 commit 93ab1f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
8 changes: 5 additions & 3 deletions test/acceptance/checkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
})
));

Expand Down

0 comments on commit 93ab1f9

Please sign in to comment.