𝙇𝙆
Size: a a a
𝙇𝙆
S
S
S
ЯВ
ШН
T
D
ШН
T
ШН
/// <summary>
/// Get and return a mapped response with authorization header
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="http"></param>
/// <returns></returns>
public static async Task<Result<TResponse>> GetWithAuthAsync<TResponse>(this HttpClient http, ILogger logger, string url, AuthenticationHeaderValue authHeaderValue)
{
if (http == null) throw new ArgumentNullException(nameof(http));
if (authHeaderValue == null) throw new ArgumentNullException(nameof(authHeaderValue));
using var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = authHeaderValue;
try
{
using var response = await http.SendAsync(request);
if (response.IsSuccessStatusCode)
{
return Result.Create(JsonConvert.DeserializeObject<TResponse>(await response.Content.ReadAsStringAsync()));
}
return response.ReasonPhrase;
}
catch (Exception ex)
{
logger.LogError(ex, "GET with AUTH request error to {0}", url);
#if DEBUG
return ex.Message;
#else
return "Service is unavailable";
#endif
}
}
ШН
D