Swiss Army Knife
General utility tools for Scada Minds
Static Public Member Functions | List of all members
HttpResponseMessageExtensions Class Reference

Methods for working with more efficiently with HttpResponses. More...

Static Public Member Functions

static async Task EnsureSuccessStatusCodeOrLogAsync (this HttpResponseMessage message, Action< HttpRequestException, string > beforeThrowing)
 Ensures that the HttpResponse returns with an OK status code. If it does not, it will call the "beforeThrowing" function, and then throw a HttpRequestException. It will pass the error and the request body as a string into the orElseFunction. More...
 

Detailed Description

Methods for working with more efficiently with HttpResponses.

Member Function Documentation

◆ EnsureSuccessStatusCodeOrLogAsync()

static async Task EnsureSuccessStatusCodeOrLogAsync ( this HttpResponseMessage  message,
Action< HttpRequestException, string >  beforeThrowing 
)
inlinestatic

Ensures that the HttpResponse returns with an OK status code. If it does not, it will call the "beforeThrowing" function, and then throw a HttpRequestException. It will pass the error and the request body as a string into the orElseFunction.

It basically works like EnsureStatusCode, except that it gives you a logging hook.

Parameters
messageThe HttpResponseMessage to ensure is valid.
beforeThrowingThe function to be called if the request was not successful. This will get passed the HttpRequestException, and the response body. You do not need to throw the error.

The documentation for this class was generated from the following file: