Skip to content

Commit 0db52d5

Browse files
committed
Fix message handling for errors raised from HRESULT or WinHTTP.
Fixes #142
1 parent 2f864b7 commit 0db52d5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/_native/helpers.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ void err_SetFromWindowsErrWithMessage(int error, const char *message, const wcha
5151
cause = PyErr_GetRaisedException();
5252
}
5353

54+
if ((error & 0xFFFF0000) == 0x80070000) {
55+
// Error code is an HRESULT containing a regular Windows error
56+
error &= 0xFFFF;
57+
}
58+
if (!hModule && error >= 12000 && error <= 12184) {
59+
// Error codes are from WinHTTP, which means we need a module
60+
hModule = GetModuleHandleW(L"winhttp");
61+
}
62+
5463
if (!os_message) {
5564
DWORD len = FormatMessageW(
5665
/* Error API error */

0 commit comments

Comments
 (0)