mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-09 06:34:53 +03:00
added try/catch for JSON parsing and fail fast approach if JSON is invalid
This commit is contained in:
parent
c0a4bb78e9
commit
38483a4029
13
cli/index.ts
13
cli/index.ts
|
@ -357,8 +357,13 @@ function handleError(error: Error) {
|
|||
}
|
||||
|
||||
function getObjectOrJSON(options) {
|
||||
return options && typeof options === 'string'
|
||||
? JSON.parse(options) : options
|
||||
? options
|
||||
: {};
|
||||
try {
|
||||
return options && typeof options === 'string'
|
||||
? JSON.parse(options) : options
|
||||
? options
|
||||
: {};
|
||||
} catch (e) {
|
||||
console.log(`Encountered error:\n${options}\nis not a valid JSON.`);
|
||||
handleError(e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user