2022-06-15 21:17:21 +03:00
|
|
|
// Copyright 2022 Valters Melnalksnis
|
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
// See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2022-08-29 22:16:06 +03:00
|
|
|
namespace VMelnalksnis.NordigenDotNet.Serialization;
|
2022-06-15 21:17:21 +03:00
|
|
|
|
|
|
|
|
internal static class HttpResponseMessageExtensions
|
|
|
|
|
{
|
|
|
|
|
internal static async Task ThrowIfNotSuccessful(this HttpResponseMessage response)
|
|
|
|
|
{
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
2022-11-09 21:57:31 +02:00
|
|
|
#if NET6_0_OR_GREATER
|
2022-06-15 21:17:21 +03:00
|
|
|
throw new HttpRequestException(content, null, response.StatusCode);
|
2022-11-09 21:57:31 +02:00
|
|
|
#else
|
|
|
|
|
throw new HttpRequestException(content);
|
|
|
|
|
#endif
|
2022-06-15 21:17:21 +03:00
|
|
|
}
|
|
|
|
|
}
|