Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Source/UrlRequest_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ namespace UrlLib
return LoadHttpAsync();
}
}
catch (winrt::hresult_error)
catch (const winrt::hresult_error& error)
{
// Catch WinRT exceptions, but retain the default status code of 0 to indicate a client side error.
// Retain the default status code of 0 to indicate a client-side (transport)
// error, but record the WinRT failure via SetError -- consistent with the
// curl/NSURL backends -- so it is diagnosable through
// ErrorString()/ErrorSymbol()/ErrorCode() instead of being silently discarded.
std::ostringstream symbol;
symbol << "0x" << std::hex << std::uppercase << static_cast<uint32_t>(error.code());
SetError("winrt", symbol.str(), static_cast<int32_t>(error.code()), winrt::to_string(error.message()));
return arcana::task_from_result<std::exception_ptr>();
}
}
Expand Down
17 changes: 16 additions & 1 deletion Source/UrlRequest_Windows_Shared.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "UrlRequest_Base.h"

#include <sstream>
#include <Unknwn.h>
#include <PathCch.h>
#include <arcana/threading/task_conversions.h>
Expand Down Expand Up @@ -53,7 +54,21 @@ namespace UrlLib
#endif

m_method = method;
m_uri = Foundation::Uri{winrt::to_hstring(url)};
try
{
m_uri = Foundation::Uri{winrt::to_hstring(url)};
}
catch (const winrt::hresult_error& error)
{
// Foundation::Uri rejects some inputs (e.g. malformed or unsupported URLs)
// by throwing a WinRT hresult_error, which is not a std::exception. Rethrow
// as std::runtime_error so callers (e.g. the XMLHttpRequest polyfill) surface
// the real reason instead of a generic "Unknown error opening URL".
std::ostringstream message;
message << "Unable to open URL '" << url << "': " << winrt::to_string(error.message())
<< " (HRESULT 0x" << std::hex << std::uppercase << static_cast<uint32_t>(error.code()) << ")";
Comment on lines +67 to +69
throw std::runtime_error{message.str()};
}
}

arcana::task<void, std::exception_ptr> SendAsync();
Expand Down