Detect JSON APIs returning HTML content-type

This commit is contained in:
Gregory Schier
2024-08-29 10:52:41 -07:00
parent 0d20e0fe29
commit f8936e7b76
5 changed files with 66 additions and 21 deletions

View File

@@ -14,3 +14,12 @@ export function languageFromContentType(contentType: string | null): EditorProps
return 'text';
}
}
export function isJSON(text: string): boolean {
try {
JSON.parse(text);
return true;
} catch (_) {
return false;
}
}