Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error in match & allocate service crashing app (#869)
https://eaflood.atlassian.net/browse/WATER-4375 Spotted whilst working on [Fix licence issues failing to insert for review](#867). When `PersistAllocatedLicenceToResultsService` errored trying to insert a record it was causing an uncaught exception that was crashing the app. After investigating the issue we have spotted it is because `MatchAndAllocateService` is using a `forEach()` to call asynchronous code. - [Using async/await in a forEach loop (you can't)](https://blog.devgenius.io/using-async-await-in-a-foreach-loop-you-cant-c174b31999bd) - [Do not use forEach with async-await](https://gist.github.com/joeytwiddle/37d2085425c049629b80956d3c618971) If we switch to a `for...of` loop instead any errors thrown within the loop, even from `PersistAllocatedLicenceToResultsService` get caught as expected by the top level `try/catch` in `ProcessBillRun` and the bill run marked as errored. Also, whilst looking into this we spotted that `DetermineLicenceIssuesService` has been made `async` even though it is doing nothing asynchronous. We use this opportunity to fix that as well.
- Loading branch information