Skip to content

Commit

Permalink
chore: updating the changelog and using constants for some values
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinCanton committed Jan 28, 2024
1 parent 659288f commit 4f0bcdf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ All notable changes to this project will be documented in this file. See [Conve
- **runtime**: updating the .net version support for net8.0, and removing native support for netstandard2.1 and net5.0 ([#58](https://github.com/JustinCanton/Geo.NET/issues/58)) ([4398a10](https://github.com/JustinCanton/Geo.NET/commit/4398a10afb21d3e7e86fba0fa4052adb67ca1faa))
- **serialization**: updating to use System.Text.Json instead of Newtonsoft.Json ([#40](https://github.com/JustinCanton/Geo.NET/issues/40)) ([e108ec6](https://github.com/JustinCanton/Geo.NET/commit/e108ec65d895d8d7fa792845973f14cdcc7335ae))
- **exceptions**: updating how exceptions are handled and removing unused interfaces ([#95](https://github.com/JustinCanton/Geo.NET/issues/95)) ([61a3e5f](https://github.com/JustinCanton/Geo.NET/commit/61a3e5f1b8bb2bd74cd7b11e92c91bcaf1e691ac))
- **configuration**: updating to allow services to pass a key when sending requests and changing how option information is configured and stored ([#80](https://github.com/JustinCanton/Geo.NET/issues/80)) ([61a3e5f](https://github.com/JustinCanton/Geo.NET/commit/61a3e5f1b8bb2bd74cd7b11e92c91bcaf1e691ac))
- **configuration**: updating to allow services to pass a key when sending requests and changing how option information is configured and stored ([#80](https://github.com/JustinCanton/Geo.NET/issues/80)) ([659288f](https://github.com/JustinCanton/Geo.NET/commit/659288f178605333cf43e81a624591d53ef48e22))

## [1.6.0](https://github.com/JustinCanton/Geo.NET/compare/1.5.2...1.6.0) (2023-12-29)
### Features
Expand Down
33 changes: 33 additions & 0 deletions src/Geo.Core/ErrorResponseFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <copyright file="ErrorResponseFields.cs" company="Geo.NET">
// Copyright (c) Geo.NET.
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information.
// </copyright>

namespace Geo.Core
{
/// <summary>
/// The fields added to a response exception in cases of failure.
/// </summary>
internal static class ErrorResponseFields
{
/// <summary>
/// The uri of the endpoint called.
/// </summary>
public const string Uri = "uri";

/// <summary>
/// The body of the request sent to the endpoint.
/// </summary>
public const string RequestBody = "requestBody";

/// <summary>
/// The status code of the response from the endpoint.
/// </summary>
public const string ResponseStatusCode = "responseStatusCode";

/// <summary>
/// The body of the response from the endpoint.
/// </summary>
public const string ResponseBody = "responseBody";
}
}
10 changes: 5 additions & 5 deletions src/Geo.Core/GeoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,19 @@ internal async Task<TResult> CallAsync<TResult>(
if (!response.IsSuccessful)
{
var ex = new GeoNETException(string.Format(CultureInfo.InvariantCulture, Resources.GeoClient.Request_Failed, ApiName));
ex.Data.Add("uri", uri);
ex.Data.Add(ErrorResponseFields.Uri, uri);

if (method == HttpMethod.Post && content != null)
{
#if NETSTANDARD2_0
ex.Data.Add("requestBody", await content.ReadAsStringAsync().ConfigureAwait(false));
ex.Data.Add(ErrorResponseFields.RequestBody, await content.ReadAsStringAsync().ConfigureAwait(false));
#else
ex.Data.Add("requestBody", await content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));
ex.Data.Add(ErrorResponseFields.RequestBody, await content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));
#endif
}

ex.Data.Add("responseStatusCode", response.StatusCode);
ex.Data.Add("responseBody", response.Body);
ex.Data.Add(ErrorResponseFields.ResponseStatusCode, response.StatusCode);
ex.Data.Add(ErrorResponseFields.ResponseBody, response.Body);

_logger.ApiCallFailed(uri, ex);

Expand Down
8 changes: 4 additions & 4 deletions test/Geo.Core.Tests/GeoClientShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public async Task ReturnsErrorJson()
.Should()
.ThrowAsync<GeoNETException>())
.WithMessage("The Test request failed.")
.And.Data["responseBody"].Should().Be("{'Message':'Access denied'}");
.And.Data[ErrorResponseFields.ResponseBody].Should().Be("{'Message':'Access denied'}");
}

/// <summary>
Expand Down Expand Up @@ -297,9 +297,9 @@ public void ThrowWrappedExceptionOnErrorJson()
.ThrowAsync<GeoNETException>()
.Where(x =>
x.Data.Count == 3 &&
x.Data["responseBody"].ToString() == "{'Message':'Access denied'}" &&
(HttpStatusCode)x.Data["responseStatusCode"] == HttpStatusCode.Forbidden &&
x.Data["uri"].ToString() == "http://test.com/Failure");
x.Data[ErrorResponseFields.ResponseBody].ToString() == "{'Message':'Access denied'}" &&
(HttpStatusCode)x.Data[ErrorResponseFields.ResponseStatusCode] == HttpStatusCode.Forbidden &&
x.Data[ErrorResponseFields.Uri].ToString() == "http://test.com/Failure");
}

/// <summary>
Expand Down

0 comments on commit 4f0bcdf

Please sign in to comment.