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,13 +36,19 @@ module.exports = async function (context, req) {
redirect(context, segment, tokens, '');
} catch (error) {
if (!error.stack) {
redirect(context, segment, tokens, toBase64(error));
return;
}
context.log(`Error: ${error.stack}`);
let buff = Buffer.from(error.stack);
let message = buff.toString('base64');
redirect(context, segment, tokens, message);
redirect(context, segment, tokens, toBase64(error.stack));
}
}
function toBase64(str) {
return Buffer.from(str).toString('base64');
}
function redirect(context, segment, tokens, error) {
const url = `${process.env['DOCS_LOCATION']}/docs/auth?segment=${segment}&access_token=${tokens.access_token}&refresh_token=${tokens.refresh_token}&expires_in=${tokens.expires_in}&error=${error}`;
context.res = {