When parsing expected JSON input, I use a try catch statement to determine whether or not the response body is indeed JSON, and store this in a variable:
let noParseErr = true;
try {
JSON.parse(body);
} catch (err) {
console.error(err);
noParseErr = false;
} finally {
if (noParseErr) {
// do stuff
}
}
Is there a better approach to this?