Hot answers tagged

5

The code could be improved with a few tweaks, but it's not bad, and the overall structure looks just fine to me. Error handling is in the wrong place Some of your route handler are async, and inside them you await. Whenever you have a Promise, make sure to handle possible errors properly. Although the functions outside of your router handlers handle errors - ...


5

Test case structure It doesn't seem like the code totally "lacked effort and structure" but the structure, at least of the test cases, could be better. Since all three describe() blocks contain a test that calls getLatlonFromPostcode so there could be a single describe() block with three it() blocks to test the various aspects of how the function ...


4

Your code boils down to just executing getGroups() in parallel with the getProfile()-getStatusText() sequence. You might want to extract that sequence out to a separate function. This way, it's obvious that they're treated as one thing (two async calls build one object). You can then Promise.all() the return of this new function (getStatus() in the following ...


4

When you have multiple asynchronous requests to make, and you want them to operate in parallel, usually the appropriate tool to use is Promise.all. You can use it here to wait for the groups and the profile data at once, despite the fact that the two requests are pretty distinct from each other: async function gatherUserInfo(userId) { try { const [...


2

Module inclusion Some style guides recommend using import instead of require - e.g. the AirBnB style guide, and also recommend putting import statements above non-import statements (AirBnB, Google). Why? Since imports are hoisted, keeping them all at the top prevents surprising behavior. 1 Indentation Levels The function start() contains a call to ...


1

It is difficult to tell "which one is better". As Jan mentioned in a comment: "tell which one is better" - what does "better" mean? performance? code readability? ... ? The notion of better is subjective. I am drawn to the first solution as it uses the fewest lines, though readability suffers because the lines are quite long ...


Only top voted, non community-wiki answers of a minimum length are eligible