Skip to content

Commit a9861cb

Browse files
committed
Improved win32 error reporting via http_exception (now looks like 'WinHTTPFunctionName: 418: I am a teapot')
1 parent 0a4b6a9 commit a9861cb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Release/src/http/client/http_win7.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static void parse_winhttp_headers(HINTERNET request_handle, _In_z_ utf16char *he
107107
static std::string build_callback_error_msg(_In_ WINHTTP_ASYNC_RESULT *error_result)
108108
{
109109
std::stringstream error_msg;
110-
error_msg << "Error [" << GetLastError() << "] in: ";
111110
switch(error_result->dwResult)
112111
{
113112
case API_RECEIVE_RESPONSE:
@@ -129,6 +128,20 @@ static std::string build_callback_error_msg(_In_ WINHTTP_ASYNC_RESULT *error_res
129128
error_msg << "Unknown WinHTTP Function";
130129
break;
131130
}
131+
error_msg << ": " << error_result->dwError << ": ";
132+
std::array<char, 256> buf = { 0 };
133+
134+
auto hr = ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
135+
NULL,
136+
error_result->dwError,
137+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
138+
buf.data(),
139+
buf.size() - 1,
140+
NULL);
141+
if (hr == 0)
142+
error_msg << buf.data();
143+
else
144+
error_msg << "?";
132145
return error_msg.str();
133146
}
134147

Release/src/pch/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
#include <assert.h>
9494
#include <streambuf>
9595
#include <mutex>
96+
#include <array>
9697

9798
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
9899
#include <ppltasks.h>

0 commit comments

Comments
 (0)