* refactor(getCitations.js): add null check for adaptiveCards variable before accessing its properties (#232)

This commit is contained in:
Youth 2023-05-11 09:23:15 +08:00 committed by GitHub
parent b466b36e7a
commit 7997c3137a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,8 @@
const regex = / \[.*?]\(.*?\)/g; const regex = / \[.*?]\(.*?\)/g;
const getCitations = (res) => { const getCitations = (res) => {
const textBlocks = res.details.adaptiveCards[0].body; const adaptiveCards = res.details.adaptiveCards;
const textBlocks = adaptiveCards && adaptiveCards[0].body;
if (!textBlocks) return ''; if (!textBlocks) return '';
let links = textBlocks[textBlocks.length - 1]?.text.match(regex); let links = textBlocks[textBlocks.length - 1]?.text.match(regex);
if (links?.length === 0 || !links) return ''; if (links?.length === 0 || !links) return '';