/jserror: Refactor to handle errors better
parent
788eb86d84
commit
e909072776
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue