Skip to content

Commit 400ee86

Browse files
committed
More resilient checks on retrieved JSON
1 parent b2b542f commit 400ee86

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/extension.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,18 @@ async function getJSONwithEmbeddedContext(json_document: vscode.TextDocument) {
571571
})
572572
console.log(response);
573573

574-
if(response.headers['content-type'] != 'application/json' || response.headers['content-type'] != 'text/json' || response.headers['content-type'] != 'application/ld+json') {
574+
if(response.headers['content-type'] != 'application/json' && response.headers['content-type'] != 'text/json' && response.headers['content-type'] != 'application/ld+json') {
575575
throw new Error("Service did not return JSON content type: " + response.headers['content-type']);
576576
}
577577

578-
const remote_context = response.data;
578+
579+
var remote_context = response.data;
580+
581+
if (typeof remote_context == 'string'){
582+
// Ensure that the returned response can be parsed as data
583+
remote_context = JSON.parse(remote_context);
584+
}
585+
579586
outputChannel.appendLine("Preloaded context from " + context[c]);
580587
expandedContextArray.push(remote_context);
581588
} catch (e: any){

0 commit comments

Comments
 (0)