Skip to content

Commit

Permalink
#2 catch possible errors from json conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Raisel Melian committed Jan 25, 2019
1 parent 219822b commit f09bd7e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ const command = async (specFilePath, targetFormat) => {
process.exit(1);
}

const document = await converter.convert(specFilePath, targetFormat);
console.log(document);
try {
const document = await converter.convert(specFilePath, targetFormat);
console.log(document);
}catch (e) {
console.error(e);
}

};


Expand Down
2 changes: 1 addition & 1 deletion lib/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
const parser = require('./parser');
const YAML = require('js-yaml');


const formats = Object.freeze({
JSON: "json",
YAML: "yaml"
});

function convertToJson(content) {

let jsonObject = JSON.parse(content);

return YAML.safeDump(jsonObject);
Expand Down
2 changes: 1 addition & 1 deletion test/samples/asyncapi.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"asyncapid": "1.2.0",
"asyncapi": "1.2.0",
"info": {
"title": "Streetlights API",
"version": "1.0.0",
Expand Down

0 comments on commit f09bd7e

Please sign in to comment.