Skip to content

Commit

Permalink
more graceful error handling when reading file
Browse files Browse the repository at this point in the history
  • Loading branch information
dtobe committed Jul 23, 2019
1 parent ebc0f4a commit 4a4e9b1
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions standalone/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
const getPort = require("get-port");
const argv = require("yargs").argv;
const getPort = require('get-port');
const argv = require('yargs').argv;
const fs = require('fs');

const AietesServer = require("../mock-server");
const AietesServer = require('../mock-server');

standalone = async () => {
console.info("Starting Aietes standalone");
const standalone = async() => {
console.info('Starting Aietes standalone');

const port = argv.port || await getPort();
const port = argv.port || await getPort();

const responseFileName = argv.json;
let jsonResponse;
if (responseFileName) {
jsonResponse = JSON.parse(await fs.readFile(responseFileName, 'utf8'));
const responseFileName = argv.json;
let jsonResponse;
if (responseFileName) {
try {
jsonResponse = JSON.parse(fs.readFileSync(responseFileName, 'utf8'));
} catch (err) {
console.error(err.message);
console.error(`Reading response definition file '${responseFileName}' failed. Aietes exiting.`);
process.exit(1);
}
}
const response = jsonResponse || {
'/': {
get: {
status: 200,
headers: {},
data: { hello: 'Aietes' }
}
}
};

const response = jsonResponse || {
"/": {
get: {
status: 200,
headers: {},
data: { hello: "Aietes"}
}
}
};
const standaloneMock = new AietesServer(response, port);
standaloneMock.start();
const standaloneMock = new AietesServer(response, port);
standaloneMock.start();
};

module.exports = standalone();
module.exports = standalone();

0 comments on commit 4a4e9b1

Please sign in to comment.