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

Update Members API error handling and Application Insights events #1462

Merged
merged 4 commits into from
Mar 27, 2024

Conversation

mec
Copy link
Collaborator

@mec mec commented Mar 27, 2024

We are seeing some Members API errrors in production that are stopping some view and exports from completing, this work is mosly focused on resolving that.

We do so by making the Memeber API client always retrun the same Result object and dealing with it appropriately.

With that done, we update the Application Insights event tracking so we can better surface errors and add event tracking to the Academies API for good measure.

@mec mec force-pushed the fix/members-api-always-returns-result-object branch from 63f9267 to 2467ad2 Compare March 27, 2024 10:23
@mec mec marked this pull request as ready for review March 27, 2024 10:44
@mec mec force-pushed the fix/members-api-always-returns-result-object branch from 2467ad2 to fb657ae Compare March 27, 2024 11:25
mec added 4 commits March 27, 2024 13:28
This method returns two different objects, unlike all the other methods
for this client.

- When successful it returns the `MemberDetails` object
- When unsuccessful it returns the`Result` object (like all other
  methods in the client)

But this method is called from Project to return an MP and then we
generally guard against a nil object. In the case where this fails the
`project.member_for_constituency` is a `Result` object and not `nil` so
things go wrong further along.

The solution is to always return the `Result` object and then handle
that in the calling code.

Our first step is to return the Result with the `MemberDetails` and nil
error.

With that done, we handle the `Result` object in the calling code,
allowing a `Project` to return `nil` for `member_of_parliament` when we
cannot fetch on - which is what we want.

We tweak a couple of specs to handle this change and move on.
We want to track some other events in Application Insights so we extract
this out to a concern. At this point, it's a simple module but as a
concern it has a conventional home.
The members API client should really return a result with either an
error or the object that was fetched.

Here we take the responsibility for tracking any errors in the API call
out of the client and into the calling code, here in Project.

This means will get insight on all the errors coming from the API calls
and we only have one place to manage that.

We've made the actual error message easier to identify in
Application Insights by adding a prefix.

We've updated some of the stubbed errors to return objects instead of
their class, which is now required.
We want to surface when and why the Academies API is failing, like the
Members API we can do this at the point of use in the Project.
@mec mec force-pushed the fix/members-api-always-returns-result-object branch from fb657ae to a8996c0 Compare March 27, 2024 13:28
Copy link

sonarcloud bot commented Mar 27, 2024

@mec mec merged commit e312257 into main Mar 27, 2024
7 checks passed
@mec mec deleted the fix/members-api-always-returns-result-object branch March 27, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants