catch json body-parser errors

add note that coronacanvas doesn't count in statistics
This commit is contained in:
HF 2020-05-02 06:18:49 +02:00
parent fc7f30df7c
commit 173ad407ce
2 changed files with 12 additions and 2 deletions

View File

@ -206,6 +206,6 @@
"ranked" : false,
"req": 0,
"sd": "2020-03-15",
"desc": "Special canvas to spread aweareness of coronavirus"
"desc": "Special canvas to spread aweareness of coronavirus (doesn't count towards statistics)"
}
}

View File

@ -7,6 +7,7 @@ import bodyParser from 'body-parser';
import session from '../../core/session';
import passport from '../../core/passport';
import logger from '../../core/logger';
import { User } from '../../data/models';
import { getIPFromRequest, getIPv6Subnet } from '../../utils/ip';
@ -48,6 +49,16 @@ router.use(async (req, res, next) => {
router.use(bodyParser.json());
router.use((err, req, res, next) => {
if (err) {
logger.warn(`Got invalid json from ${req.trueIp} on ${req.originalUrl}`);
res.status(400);
res.status(400).json({ errors: [{ msg: 'Invalid Request' }] });
} else {
next();
}
});
/*
* rate limiting should occure outside,
* with nginx or whatever
@ -69,5 +80,4 @@ router.post('/mctp', mctp);
router.use('/auth', auth(passport));
export default router;