added try/catch for JSON parsing and fail fast approach if JSON is invalid

This commit is contained in:
knidarkness 2019-09-30 12:50:38 +03:00
parent c0a4bb78e9
commit 38483a4029

View File

@ -357,8 +357,13 @@ function handleError(error: Error) {
} }
function getObjectOrJSON(options) { function getObjectOrJSON(options) {
try {
return options && typeof options === 'string' return options && typeof options === 'string'
? JSON.parse(options) : options ? JSON.parse(options) : options
? options ? options
: {}; : {};
} catch (e) {
console.log(`Encountered error:\n${options}\nis not a valid JSON.`);
handleError(e);
}
} }