catch possible bad object id body.params for more friendly error

merge-requests/218/head
Thomas Lynch 3 years ago
parent 0e236a001c
commit 35ededad1e
  1. 62
      helpers/paramconverter.js

@ -81,27 +81,41 @@ module.exports = (req, res, next) => {
} }
} }
//convert checked reports to number try {
if (req.body.checkedposts) { //ids for newspost editing
req.body.checkedposts = req.body.checkedposts.map(Number); if (req.params.newsid) {
} req.params.newsid = ObjectId(req.params.newsid);
//convert checked global reports to mongoid }
if (req.body.globalcheckedposts) { if (req.body.news_id) {
req.body.globalcheckedposts = req.body.globalcheckedposts.map(ObjectId) req.body.news_id = ObjectId(req.body.news_id);
} }
if (req.body.checkednews) { //convert checked reports to number
req.body.checkednews = req.body.checkednews.map(ObjectId) if (req.body.checkedposts) {
} req.body.checkedposts = req.body.checkedposts.map(Number);
//convert checked bans to mongoid }
if (req.body.checkedbans) { //convert checked global reports to mongoid
req.body.checkedbans = req.body.checkedbans.map(ObjectId) if (req.body.globalcheckedposts) {
} req.body.globalcheckedposts = req.body.globalcheckedposts.map(ObjectId)
/* }
//convert checked reports to mongoid if (req.body.checkednews) {
if (req.body.checkedreports) { req.body.checkednews = req.body.checkednews.map(ObjectId)
req.body.checkedreports = req.body.checkedreports.map(ObjectId) }
//convert checked bans to mongoid
if (req.body.checkedbans) {
req.body.checkedbans = req.body.checkedbans.map(ObjectId)
}
/*
//convert checked reports to mongoid
if (req.body.checkedreports) {
req.body.checkedreports = req.body.checkedreports.map(ObjectId)
}
*/
} catch (e) {
return dynamicResponse(req, res, 400, 'message', {
'title': 'Bad request',
'message': 'Malformed input'
});
} }
*/
//convert duration string to time in ms //convert duration string to time in ms
for (let i = 0; i < timeFields.length; i++) { for (let i = 0; i < timeFields.length; i++) {
@ -136,17 +150,11 @@ module.exports = (req, res, next) => {
} }
} }
//ids for newspost editing
if (req.params.newsid) {
req.params.newsid = ObjectId(req.params.newsid);
}
if (req.body.news_id) {
req.body.news_id = ObjectId(req.body.news_id);
}
//thread id //thread id
if (req.params.id) { if (req.params.id) {
req.params.id = +req.params.id; req.params.id = +req.params.id;
} }
//moglog date //moglog date
if (req.params.date) { if (req.params.date) {
let [ month, day, year ] = req.params.date.split('-'); let [ month, day, year ] = req.params.date.split('-');

Loading…
Cancel
Save