Share via


HttpResponseMessage.EnsureSuccessStatusCode Method

Definition

Throws an exception if the HttpResponseMessage.IsSuccessStatusCode property for the HTTP response object is false; if it's true, then no exception is thrown.

public:
 virtual HttpResponseMessage ^ EnsureSuccessStatusCode() = EnsureSuccessStatusCode;
HttpResponseMessage EnsureSuccessStatusCode();
public HttpResponseMessage EnsureSuccessStatusCode();
function ensureSuccessStatusCode()
Public Function EnsureSuccessStatusCode () As HttpResponseMessage

Returns

If no exception is thrown, then the HTTP response object is returned.

Remarks

If the server doesn't return a successful HttpStatusCode in the Successful range (200-299) for the request, then the HttpResponseMessage.IsSuccessStatusCode property is set to false. Calling EnsureSuccessStatusCode causes the value of IsSuccessStatusCode to be checked, and an exception thrown if that value is false. No exception is thrown if the value is true.

Any exception thrown is specific to the Windows Runtime language projection that you're programming in. For C#, for example, a System.Exception is thrown, and that exception includes an HRESULT that encodes the original HTTP error. For example, if the HRESULT is 0x80190194, then remove the 0x8019000 to give 0x00000194, which is decimal 404.

To avoid dealing with exceptions, check the HttpResponseMessage.IsSuccessStatusCode property instead of calling EnsureSuccessStatusCode.

Applies to

See also