1

I would like to test whether an HttpException is a disconnected error.

A naive implementation would check the message:

bool IsClientDisconnectedError(HttpException exception)
{
   return exception.Message == "The client disconnected.";
}

How can I check for a client disconnected error without depending on the exception message?

joshuanapoli
  • 2,509
  • 3
  • 25
  • 34

1 Answers1

1

You should be able to just check the error code of the exception, documentation on HttpException here, and on ErrorCode here, with an explanation on what the arguments returned by ErrorCode mean here.


For posterity, if you don't want to read the comments below this answer, it's also possible to try logging the Source and HttpCode to gather more information and find a unique code for a particular exception.

R. McManaman
  • 304
  • 2
  • 14
  • I think that the ErrorCode is E_FAIL "Unspecified failure". How can I tell that this code uniquely corresponds to "The client disconnected."? – joshuanapoli May 24 '17 at 14:18
  • Could you try printing `exception.Source` to the console? I'm kind of curious if something else might be going on. It should display the name of the application or the object that causes the error. – R. McManaman May 24 '17 at 14:24
  • 1
    I'll try logging the Source, ErrorCode and HttpCode to see if any of these give a specific way to test for the "client disconnected" condition. – joshuanapoli May 24 '17 at 14:35
  • Awesome, let me know how it goes! – R. McManaman May 24 '17 at 14:42