Lab 3 — DPS909

Ekaterina Grinberg
2 min readOct 9, 2020

--

Git merges

For this lab, we required to add 2 additional features to our Release 0.1. Each feature should be created on the separate branch. In the end, the branches should be merged into the master branch.

I decided to add the following features:

  • Add a flag to produce JSON response. Now user can select on the option to print all the links and their statuses in JSON format. I created issue-4 for this feature in my repo.
  • Add appropriate error code when the program exits. If all links are good then program exits with status code 0, otherwise, the program exits with error code 1. I created issue-5 for this feature in my repo.

First I started working on adding the JSON response feature. I created a separated branch called issue-4. In order to create a JSON response that includes all the links with their statuses, I created an array that stores all JSON objects. Then I created a JSON object inside the forEach method ( which iterates through all the links and send a request by using the fetch method) that includes the URL info and the response status. Then I added each JSON object to the previously created array. Here I got into a problem when I printed the array of JSON objects it was empty. I figure that the reason for this behaviour is that the code after the forEach loop is executed without waiting for the responses from each asynchronous function that sends the URL request. I started to research about it and found the answer in StackOverflow. In one of the comments, it says

Each of the async callback function calls does return a promise, but you're throwing them away instead of awaiting them. Just use map instead, and you can await the array of promises that you'll get with Promise.all. (link to the comment)

I implemented the suggested solution and it worked perfectly. Now the program was waiting to receive the response from all the requests and only after receiving all the promises it continues to execute the rest of the code.

The second feature was simply adding a function that loops through the array of JSON objects and check if the array has an URL with bad response. If URL with bad response found the function returns 1 otherwise returns 0. This function call within the : process.exit(checkStatus(jsonResponse));

After completing the implementation of all the features , I commited the changes to the corresponsing branches and merged it to the master branch.

The commit links are listed below:

  1. Appropriate error code is added when program is exit
  2. Added flag to print response in JSON format

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response