mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
/jserror: Refactor to handle errors better
This commit is contained in:
parent
788eb86d84
commit
e909072776
1 changed files with 10 additions and 9 deletions
|
@ -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
|
// The Etherpad client side sends information about client side javscript errors
|
||||||
args.app.post('/jserror', (req, res) => {
|
args.app.post('/jserror', (req, res, next) => {
|
||||||
new formidable.IncomingForm().parse(req, (err, fields, files) => {
|
(async () => {
|
||||||
let data;
|
const data = JSON.parse(await parseJserrorForm(req));
|
||||||
try {
|
|
||||||
data = JSON.parse(fields.errorInfo);
|
|
||||||
} catch (e) {
|
|
||||||
return res.end();
|
|
||||||
}
|
|
||||||
clientLogger.warn(`${data.msg} --`, data);
|
clientLogger.warn(`${data.msg} --`, data);
|
||||||
res.end('OK');
|
res.end('OK');
|
||||||
});
|
})().catch((err) => next(err || new Error(err)));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Provide a possibility to query the latest available API version
|
// Provide a possibility to query the latest available API version
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue