0

I have my WebResponse wrapped in using blocks:

using (var response = request.GetResponse())
{
// do things...
}

The webservice I'm calling will raise 429's with a Retry-After in the header.

If I wrap this in a try-catch to listen for the WebException then I will lose the context of the response and won't be able to read the Retry-After element in the header.

How should I properly handle the response while also implementing retry logic for this?

Community
  • 1
  • 1
Matthew
  • 10,244
  • 5
  • 49
  • 104

1 Answers1

0

Actually it was much easier than I thought.

The WebException class exposes a .Response property which I can use to read the items in the response (if any was sent).

Matthew
  • 10,244
  • 5
  • 49
  • 104