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

Add ApiExceptionDestructurer for Refit.ApiException (Refit NuGet) #398

Merged
merged 8 commits into from
Sep 28, 2021

Conversation

git-heath
Copy link

@git-heath git-heath commented Sep 21, 2021

resolves #396

@git-heath
Copy link
Author

Pull request based on existing implementations of ExceptionDestructurer, however I overloaded the constructor public ApiExceptionDestructurer(bool destructureCommonExceptionProperties = true) which deviates from other implementations.

Also the NuGet links in the documentation are for the moment simply placeholders, I wasn't sure what to do for them.

@RehanSaeed RehanSaeed requested a review from krajek September 22, 2021 08:23
Copy link
Owner

@RehanSaeed RehanSaeed left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Taking a look.

@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31423.177
# Visual Studio Version 16
Copy link
Owner

Choose a reason for hiding this comment

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

Can we keep version 17?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I put it back to 17 for you.

#pragma warning disable CA1062 // Validate arguments of public methods
var apiException = (ApiException)exception;
propertiesBag.AddProperty(nameof(ApiException.Uri), apiException.Uri);
propertiesBag.AddProperty(nameof(ApiException.Content), apiException.Content);
Copy link
Owner

Choose a reason for hiding this comment

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

I've not used Refit before. Does ApiException.Content effectively contain the response body? That could potentially be very large and maybe something you wouldn't want to log by default.

Copy link
Author

Choose a reason for hiding this comment

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

Yes this is the HTTP response body. Yes I hesitated on this property, this could potentially be very large. I could add an option in the constructor bool destructureContent with a default of false ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably content should be destructured, that's fine. Maybe we should just limit the payload to some reasonable limit (like 2kb) and let user configure otherwise.

Copy link
Owner

Choose a reason for hiding this comment

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

All logging frameworks used by ASP.NET omit the content. We should do the same by default and provide an option to enable it.

Copy link
Author

Choose a reason for hiding this comment

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

I made it optional (default disabled). Let me know if this is ok and I will add some tests for it.

README.md Outdated
```csharp
.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithDestructurers(new[] { new ApiExceptionDestructurer(destructureCommonExceptionProperties = false) }))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just asking, shouldn't it be destructureCommonExceptionProperties: false

Copy link
Author

Choose a reason for hiding this comment

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

Absolutely, well spotted. Now corrected, also added docmentation for the other optional constructor parameter.

Copy link
Collaborator

@krajek krajek left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution.

@RehanSaeed
Copy link
Owner

LGTM.

@RehanSaeed RehanSaeed merged commit 7d2b58b into RehanSaeed:main Sep 28, 2021
@RehanSaeed RehanSaeed added enhancement Issues describing an enhancement or pull requests adding an enhancement. minor Pull requests requiring a minor version update according to semantic versioning. labels Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues describing an enhancement or pull requests adding an enhancement. minor Pull requests requiring a minor version update according to semantic versioning.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add destructurer for Refit ApiException
3 participants