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

Datapusher fixes #356

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Datapusher fixes #356

wants to merge 17 commits into from

Conversation

gcsantos-gpa
Copy link
Contributor

@gcsantos-gpa gcsantos-gpa commented Sep 18, 2024

Copy link
Member

@StephenCWills StephenCWills left a comment

Choose a reason for hiding this comment

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

Do we need to continue to support the legacy UserAccount authentication? Seems to me like what we should do is fully switch over to APIQuery and then maybe adjust authorization rules to disallow DataPusher requests from regular users.

@gcsantos-gpa
Copy link
Contributor Author

Do we need to continue to support the legacy UserAccount authentication? Seems to me like what we should do is fully switch over to APIQuery and then maybe adjust authorization rules to disallow DataPusher requests from regular users.

The intention, as I understand it, was to not disrupt legacy behavior or create a breaking change.

@StephenCWills
Copy link
Member

Can we go ahead and create a breaking change then? IMO, we can fix the errors at GTC/GPC easily enough, but we have no process for removing the legacy behavior later.

Copy link
Member

@StephenCWills StephenCWills left a comment

Choose a reason for hiding this comment

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

Really excellent cleanups in this PR. I like where this is headed. I just noticed a couple problematic patterns that were repeated several times. They should be easy enough to clear up.

Source/Libraries/openXDA.DataPusher/DataPusherEngine.cs Outdated Show resolved Hide resolved
Source/Libraries/openXDA.DataPusher/DataPusherEngine.cs Outdated Show resolved Hide resolved
Comment on lines 63 to 64
if (!response.IsSuccessStatusCode)
throw new InvalidOperationException($"Server returned status code {response.StatusCode}: {response.ReasonPhrase}");
Copy link
Member

Choose a reason for hiding this comment

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

I know this pattern wasn't introduced this PR, but now seems like a good time to switch to response.EnsureSuccessStatusCode().

Suggested change
if (!response.IsSuccessStatusCode)
throw new InvalidOperationException($"Server returned status code {response.StatusCode}: {response.ReasonPhrase}");
response.EnsureSuccessStatusCode();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did so, out of curiosity and ignorance, why is this a bad pattern?

Copy link
Member

Choose a reason for hiding this comment

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

response.EnsureSuccessStatusCode() will throw an HttpResponseException, I believe. Exception handlers will be more likely to expect it. For example, and if I'm not mistaken, the HTTP status code would be passed through to the client automatically by ApiController handlers.

It also reduces nesting, which typically makes the code more readable.

Source/Libraries/openXDA.DataPusher/WebAPIHub.cs Outdated Show resolved Hide resolved
Source/Libraries/openXDA.DataPusher/WebAPIHub.cs Outdated Show resolved Hide resolved
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