0

I try to handle custom HTTP status code like 444 or 429 that are not in the HttpStatusCode enum when receving them with a WebException ( (ex.Response as HttpWebResponse).StatusCode ).

Is there a better way than parsing response as suggested in this answer HttpWebResponse Status Code 429 ?

As there are many of them, this solution is not suitable.

SeyoS
  • 661
  • 5
  • 22

1 Answers1

1

Just cast the StatusCode to int:

int code = (int)((ex.Response as HttpWebResponse).StatusCode);
if(code == 429)
{
    ...
}

this will work even if there isn't a corresponding enum value because in C# enums are not checked.

Alberto
  • 15,626
  • 9
  • 43
  • 56