Reputation: 75
I'm looking at developing a COM wrapper library in C++ for an RESTful web service, and would like to know if there is any standard approach for mapping HTTP Status code values to HRESULTs that will be returned over the COM API. I've had a scan through the definitions in WinError.h, but don't see anything that is appropriate. I know that you can define your own range of HRESULT values, but (as always) I'd prefer to go with a standard approach if one exists.
Thanks for any help in advance.
Upvotes: 1
Views: 1313
Reputation: 241
Windows SDK 8.0 introduced HRESULT
s for almost all the HTTP status code in winerror.h
, for example:
#define HTTP_E_STATUS_NOT_FOUND _HRESULT_TYPEDEF_(0x80190194L)
If you examined all the values for HTTP_E_*
, you may found that the error code part of HRESULT
is just the HTTP status code. Then, you may define a macro for converting any http status code to HRESULT:
#define HRESULT_FROM_HTTP(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_HTTP, code)
Upvotes: 0
Reputation: 3112
One way is to use BitsMsg.h from Microsoft SDK for a set of HTTP Status codes
e.g. 404 is defined as:
#define BG_E_HTTP_ERROR_404 0x80190194L
// ^^ The requested URL does not exist on the server.
To view these codes online, use the following links: HRESULTS: FACILITY_HTTP or BitsMsg.h
Upvotes: 2