Skip to content

Commit 855975d

Browse files
author
Adam Koniar
committed
Modify check the empty payload and a test
1 parent 8a4b3aa commit 855975d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Diff for: app.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ const fruits = require('./lib/routes/fruits');
3131

3232
app.use(bodyParser.json());
3333
app.use(function (error, req, res, next) {
34-
console.log(error);
35-
if (error instanceof SyntaxError && error.type === 'entity.parse.failed') {
34+
if (req.body === '' || (error instanceof SyntaxError && error.type === 'entity.parse.failed')) {
3635
res.status(415);
3736
return res.send('Invalid payload!');
3837
} else {

Diff for: test/fruits-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ test('test PUT fruit - error - invalid payload', (t) => {
524524

525525
supertest(app)
526526
.put('/api/fruits/20')
527+
.set('Content-Type', 'application/json')
527528
.send('Some text')
528529
.expect(415)
529530
.then(response => {

0 commit comments

Comments
 (0)