invalid JSON error handling

This commit is contained in:
Alexey 2019-07-24 20:19:00 +03:00
parent 918c5b0f7a
commit 91c109b902

View File

@ -4,6 +4,16 @@ const express = require('express')
const app = express() const app = express()
app.use(express.json()) 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) { app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*') res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept') res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')