Fix handling of Charging Module errors #96
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://eaflood.atlassian.net/browse/WATER-3833
While diagnosing an issue with Charging Module authorisation, we realised that we weren't correctly passing back any error messages it returned.
It turned out the format that errors come back in didn't quite match what we expected -- while the status code and status error (eg.
401
andUnauthorized
) are returned as part of the response, the error message we want to display (eg.Invalid JWT
) is returned in the response body in JSON format (which also contains the status code and error).We therefore update how
CreateBillRunService
returns these errors by parsing the body, and in the event of an unsuccessful request we return it as-is in the response (whereas a successful request still extracts thebillRun
object from the body and returns that as the response). This gives us the status code and status error along with any returned error message.We then amend how
InitiateBillingBatchService
formats these errors. We previously intended errors to be thrown as:We now throw them as:
(ie. status code, status error, and returned error message)
We expect to receive a message in the event of an error but if no message was returned we throw: