fix(api): print errors without stacktrace

This commit is contained in:
Jan De Dobbeleer 2022-07-12 20:43:38 +02:00 committed by Jan De Dobbeleer
parent 9e0244bc24
commit d129eaf912

View file

@ -36,11 +36,17 @@ module.exports = async function (context, req) {
redirect(context, segment, tokens, '');
} catch (error) {
context.log(`Error: ${error.stack}`);
let buff = Buffer.from(error.stack);
let message = buff.toString('base64');
redirect(context, segment, tokens, message);
if (!error.stack) {
redirect(context, segment, tokens, toBase64(error));
return;
}
context.log(`Error: ${error.stack}`);
redirect(context, segment, tokens, toBase64(error.stack));
}
}
function toBase64(str) {
return Buffer.from(str).toString('base64');
}
function redirect(context, segment, tokens, error) {