/jserror: Refactor to handle errors better

pull/5224/head
Richard Hansen 2021-10-07 19:46:07 -04:00
parent 788eb86d84
commit e909072776
1 changed files with 10 additions and 9 deletions

View File

@ -14,18 +14,19 @@ exports.expressCreateServer = (hookName, args, cb) => {
});
});
const parseJserrorForm = async (req) => await new Promise((resolve, reject) => {
const form = new formidable.IncomingForm();
form.on('error', (err) => reject(err));
form.parse(req, (err, fields) => err != null ? reject(err) : resolve(fields.errorInfo));
});
// The Etherpad client side sends information about client side javscript errors
args.app.post('/jserror', (req, res) => {
new formidable.IncomingForm().parse(req, (err, fields, files) => {
let data;
try {
data = JSON.parse(fields.errorInfo);
} catch (e) {
return res.end();
}
args.app.post('/jserror', (req, res, next) => {
(async () => {
const data = JSON.parse(await parseJserrorForm(req));
clientLogger.warn(`${data.msg} --`, data);
res.end('OK');
});
})().catch((err) => next(err || new Error(err)));
});
// Provide a possibility to query the latest available API version