Include response headers in failed requests
bernhard-hofmann opened this issue ยท 3 comments
This is a feature request.
I'd like to propose a change that will include response header details in the Data
property of the exception thrown for unsuccessful requests.
The calls to response.EnsureSuccessStatusCode()
will throw without adding headers. In the case of a 503 or 429, the Retry-After
header could be invaluable for correct behaviour on the part of the client. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
If you're in agreement, I'm offering to produce a PR that will either replace the call to the framework method (EnsureSuccessStatusCode
) or catch it, add the necessary details, and then throw it (it does other things such as dispose the content so might be worth "piggybacking").
I've opted to only include specific headers that could be required as distinct values. I've raised a PR with the enhancement for your review. :)
Thanks @bernhard-hofmann, I've merged this in and it's in the latest version of the NuGet package
https://www.nuget.org/packages/CompaniesHouse/7.11.6
Happy for you to close this issue now @kevbite. Thank you for the very swift merge and publish!