From 91c109b90293355c906e1c189b32521da826be37 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 24 Jul 2019 20:19:00 +0300 Subject: [PATCH] invalid JSON error handling --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index 812cf14..9afd396 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,16 @@ const express = require('express') const app = express() app.use(express.json()) + +app.use((err, req, res, next) => { + if (err) { + console.log('Invalid Request data') + res.send('Invalid Request data') + } else { + next() + } +}) + app.use(function(req, res, next) { res.header('Access-Control-Allow-Origin', '*') res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')