Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of Charging Module errors #96

Merged
merged 4 commits into from
Jan 24, 2023

Conversation

StuAA78
Copy link
Contributor

@StuAA78 StuAA78 commented Jan 23, 2023

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 and Unauthorized) 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 the billRun 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:

401 Invalid JWT

We now throw them as:

401 Unauthorized - Invalid JWT

(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:

401 Unauthorized

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 messges it returned. It turned out we hadn't correctly grasped the format that errors come back -- while the status code and status error are returned as part of the response, the actual error we want to display (eg. `Invalid JWT: Token format not valid`) is returned in the response body (along with the status code and error). We therefore update how we return errors.
@StuAA78 StuAA78 added the bug Something isn't working label Jan 23, 2023
@StuAA78 StuAA78 self-assigned this Jan 23, 2023
We previously returned the entire `RequestLib` response after an unsuccessful request, which included far too much inessential data and had the body in JSON format. We change how we handle unsuccessful responses to simply parse the body and return that as the response, as this gives us the status code, status error, and returned error message
We're now getting errors back from `CreateBillRunService` in the expected format, but just to cover the eventuality that an error doesn't return a message in the body, we reformat the thrown error to always return the status code and error (eg. `401` and `Unauthorized`), and optionally return the message if it exists (eg. `Invalid JWT: Token format not valid`)
@StuAA78 StuAA78 marked this pull request as ready for review January 23, 2023 13:41
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StuAA78 StuAA78 merged commit e1fff9f into main Jan 24, 2023
@StuAA78 StuAA78 deleted the fix-error-message-returned-from-charging-module branch January 24, 2023 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants