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

feat: expose HTTP response headers in InfluxDBApiException #118

Merged
merged 11 commits into from
Sep 3, 2024

Conversation

karel-rehor
Copy link
Contributor

@karel-rehor karel-rehor commented Sep 2, 2024

Proposed Changes

  • Add methods to InfluxDBApiException to get StatusCode and Headers from nested HttpResponseMessage more easily.
  • Unit tests of these changes
  • Refactor of Integration tests to leverage a base IntegrationTest class.
  • Integration test of changes to InfluxDBApiException
  • In Examples adds a General/Runner.cs class for unifying running examples.
  • In Examples adds an example for leveraging headers: HttpErrorHandled.cs.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

Copy link

codecov bot commented Sep 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.83%. Comparing base (aab7c3a) to head (d7b0502).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
+ Coverage   95.81%   95.83%   +0.02%     
==========================================
  Files          12       12              
  Lines        1098     1104       +6     
  Branches      141      143       +2     
==========================================
+ Hits         1052     1058       +6     
  Misses         11       11              
  Partials       35       35              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 19 to 28

public HttpResponseHeaders GetHeaders()
{
return HttpResponseMessage?.Headers;
}

public HttpStatusCode GetStatusCode()
{
return HttpResponseMessage?.StatusCode ?? 0;
}
Copy link
Contributor

@alespour alespour Sep 2, 2024

Choose a reason for hiding this comment

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

This could be written using property getters (invocations in tests need to be modified accordingly), is that right, @bednar?
In any case, Headers/GetHeaders return value should be nullable (T?)

Suggested change
public HttpResponseHeaders GetHeaders()
{
return HttpResponseMessage?.Headers;
}
public HttpStatusCode GetStatusCode()
{
return HttpResponseMessage?.StatusCode ?? 0;
}
public HttpResponseHeaders? Headers
{
get
{
return HttpResponseMessage?.Headers;
}
}
public HttpStatusCode StatusCode
{
get
{
return HttpResponseMessage?.StatusCode ?? 0;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. A Sensible suggestion. Updated accordingly.

"Could not parse entire line. Found trailing content: 'distance=,status=\"STOPPED\"'"
));
Assert.That(iaex.GetStatusCode().ToString(), Is.EqualTo("BadRequest"));
Assert.That(iaex.GetStatusCode().GetHashCode(), Is.EqualTo(400));
Copy link
Contributor

Choose a reason for hiding this comment

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

There is System.Net enum for status code, eg.

Suggested change
Assert.That(iaex.GetStatusCode().GetHashCode(), Is.EqualTo(400));
Assert.That(iaex.GetStatusCode(), Is.EqualTo(System.Net.HttpStatusCode.BadRequest));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, following suggestion.

Copy link
Contributor

@alespour alespour left a comment

Choose a reason for hiding this comment

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

LGTM

@karel-rehor karel-rehor merged commit fe8e214 into main Sep 3, 2024
11 checks passed
@karel-rehor karel-rehor deleted the feat/HttpErrorHeaders branch September 3, 2024 15:24
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