Deciphering HTTP Server API Error Codes
If you’ve tried using the HttpListener API to build a web server, then you may have noticed that many runtime errors come back as wrapped Win32 errors rather than different exception types. Since HttpListener doesn’t say what specific Win32 errors might occur and the underlying HTTP Server API mostly points to the list of 15,999 kinds of errors defined by WinError.h, it can be a bit of a detective job figuring out what errors might occur and can safely be handled.
I happen to have come across some notes I made a few years ago while working on our HttpListener based web server for WCF. I don’t know how many of these have changed since then or how many were even correct in the first place, but here you go for entertainment purposes only. Included is the WinError.h definition of the error code and some additional notes were applicable.
Out of memory errors- you probably shouldn’t try to recover after these as something is seriously wrong.
- ERROR_NOT_ENOUGH_MEMORY (0x8)
ERROR\_OUTOFMEMORY (0xE)
- ERROR_NO_SYSTEM_RESOURCES (0x5AA)
Less fatal, but possibly still bad, errors.
- ERROR_ACCESS_DENIED (0x5): You probably were trying to register a URL but don’t have access rights to the namespace.
ERROR\_INVALID\_HANDLE (0x6): You probably had an HTTP request going that was aborted during the response instead of gracefully closed.
- ERROR_SHARING_VIOLATION (0x20): You probably were trying to listen on a port or address that is already being used by another application.
- ERROR_NETNAME_DELETED (0x40): You probably had an HTTP request going when the underlying TCP connection was closed.
- ERROR_INVALID_PARAMETER (0x57): If this wasn’t a bug in your program, then you probably were trying to listen on a malformed URI.
- ERROR_ALREADY_EXISTS (0xB7): You probably were trying to register an address that is already registered by another application.
- ERROR_NO_TRACKING_SERVICE (0x494): HTTP.SYS or one of its dependent system services probably isn’t running.
- ERROR_ALLOTTED_SPACE_EXCEEDED (0x540): HTTP.SYS probably has too many services already registered.