catch json body-parser errors
add note that coronacanvas doesn't count in statistics
This commit is contained in:
parent
fc7f30df7c
commit
173ad407ce
|
@ -206,6 +206,6 @@
|
||||||
"ranked" : false,
|
"ranked" : false,
|
||||||
"req": 0,
|
"req": 0,
|
||||||
"sd": "2020-03-15",
|
"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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import bodyParser from 'body-parser';
|
||||||
|
|
||||||
import session from '../../core/session';
|
import session from '../../core/session';
|
||||||
import passport from '../../core/passport';
|
import passport from '../../core/passport';
|
||||||
|
import logger from '../../core/logger';
|
||||||
import { User } from '../../data/models';
|
import { User } from '../../data/models';
|
||||||
import { getIPFromRequest, getIPv6Subnet } from '../../utils/ip';
|
import { getIPFromRequest, getIPv6Subnet } from '../../utils/ip';
|
||||||
|
|
||||||
|
@ -48,6 +49,16 @@ router.use(async (req, res, next) => {
|
||||||
|
|
||||||
router.use(bodyParser.json());
|
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,
|
* rate limiting should occure outside,
|
||||||
* with nginx or whatever
|
* with nginx or whatever
|
||||||
|
@ -69,5 +80,4 @@ router.post('/mctp', mctp);
|
||||||
|
|
||||||
router.use('/auth', auth(passport));
|
router.use('/auth', auth(passport));
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user