refit
refit copied to clipboard
Impossible to read content when HTTP error code is returned
Beause of this https://github.com/reactiveui/refit/blob/main/Refit/RequestBuilderImplementation.cs#L272 it's not possible to read the body in case of an HTTP error code
Reading the body is very useful in cases when server returns error codes in the body
You could probably use something like this assuming you have a type for the error to deserialise into
/// <summary>
/// Get content from response or error.
/// </summary>
/// <typeparam name="T">Type to convert.</typeparam>
/// <param name="response">The response.</param>
/// <returns>T:from content.</returns>
public static async Task<T> GetContentAsync<T>(this ApiResponse<T> response)
{
_ = response ?? throw new ArgumentNullException(nameof(response));
return response.Content ?? await response.Error.GetContentAsAsync<T>();
}