Home > Software engineering >  How can I wrap the HTTP Request in a Success or Failure using the Task<IResult>?
How can I wrap the HTTP Request in a Success or Failure using the Task<IResult>?

Time:10-03

I'm using the HttpRequestMessage and HttpResponseMessage to obtain results from an API. For fault handling I would like to wrap it in a Success or Failure. The results come back from Task What is a good way to do this?

CodePudding user response:

The HttpResponseMessage model has a property called IsSuccessStatusCode which if true, indicates the HTTP response was successful (status codes 200-299).

You can write your own wrapper around HttpResponseMessage but why?

You don't need a wrapper in this case if all you need is a way to know if the response has succeeded or not.

Reference: MSDN - HttpResponseMessage.IsSuccessStatusCode

  • Related