From 4129d2740b0422c1c1fc3575ce429baa73c9dcb2 Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Tue, 31 Jan 2023 13:02:27 +0000 Subject: [PATCH] Fix CHA CreateBillRunService result parsing https://eaflood.atlassian.net/browse/WATER-3833 Found when working on [Add GlobalNotifier to the app](https://github.com/DEFRA/water-abstraction-system/pull/100). If we get an error response from the [SROC Charging Module API](https://github.com/DEFRA/sroc-charging-module-api) we are able to parse the result without issue. This is because it will have a JSON body. But if Got throws an exception, which it will do if it fails to get a response, for example, when the request times out then `result.response` won't have a `body` property. This is causing the `_parseResult()` method to throw an error; `Unexpected token u in JSON at position 0`. This change updates `_parseResult()` in `CreateBillRunService` to be able to handle both scenarios.