From 91b718ac16637ba3bf200396a9e7778f1b32e0c3 Mon Sep 17 00:00:00 2001 From: Akil Burgess Date: Tue, 15 Dec 2015 14:44:53 +0000 Subject: [PATCH 1/2] Update ApiExceptions to have a useful message --- .../Exceptions/ApiAuthorizationException.cs | 11 ++++++ src/GogoKit/Exceptions/ApiException.cs | 16 +------- .../Exceptions/ApiErrorExceptionTests.cs | 38 +++++++++++++++++++ tests/GogoKit.Tests/GogoKit.Tests.csproj | 1 + 4 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 tests/GogoKit.Tests/Exceptions/ApiErrorExceptionTests.cs diff --git a/src/GogoKit/Exceptions/ApiAuthorizationException.cs b/src/GogoKit/Exceptions/ApiAuthorizationException.cs index 96aff07..3b6da35 100644 --- a/src/GogoKit/Exceptions/ApiAuthorizationException.cs +++ b/src/GogoKit/Exceptions/ApiAuthorizationException.cs @@ -11,5 +11,16 @@ public ApiAuthorizationException(IApiResponse response) : ba } public AuthorizationError AuthorizationError { get; } + + public override string Message + { + get + { + var authorizationErrorResponse = Response as IApiResponse; + return authorizationErrorResponse?.BodyAsObject != null + ? authorizationErrorResponse.BodyAsObject.ErrorDescription + : base.Message; + } + } } } diff --git a/src/GogoKit/Exceptions/ApiException.cs b/src/GogoKit/Exceptions/ApiException.cs index 91662a5..82151f7 100644 --- a/src/GogoKit/Exceptions/ApiException.cs +++ b/src/GogoKit/Exceptions/ApiException.cs @@ -13,21 +13,7 @@ public ApiException(IApiResponse response) Response = response; } - public override string Message - { - get - { - string message = null; - var authorizationErrorResponse = Response as IApiResponse; - if (authorizationErrorResponse != null && - authorizationErrorResponse.BodyAsObject != null) - { - message = authorizationErrorResponse.BodyAsObject.ErrorDescription; - } - - return message ?? "An error occurred with this API request"; - } - } + public override string Message => $"An error occurred with this API request: {Response.Body}"; public IApiResponse Response { get; } } diff --git a/tests/GogoKit.Tests/Exceptions/ApiErrorExceptionTests.cs b/tests/GogoKit.Tests/Exceptions/ApiErrorExceptionTests.cs new file mode 100644 index 0000000..f52ee7a --- /dev/null +++ b/tests/GogoKit.Tests/Exceptions/ApiErrorExceptionTests.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using GogoKit.Exceptions; +using GogoKit.Models.Response; +using HalKit.Http; +using NUnit.Framework; + +namespace GogoKit.Tests.Exceptions +{ + [TestFixture] + public class ApiErrorExceptionTests + { + public static IEnumerable ApiErrorExceptionTypes + { + get + { + return typeof(ApiErrorException) + .Assembly + .GetTypes() + .Where(t => typeof(ApiErrorException).IsAssignableFrom(t) && t != typeof(ResourceNotFoundException)) + .OrderBy(t => t.Name); + } + } + + [Test, TestCaseSource(nameof(ApiErrorExceptionTypes))] + public void ApiErrorExceptions_ShouldHaveAPrettyErrorMessage(Type apiErrorExceptionType) + { + var apiResponse = new ApiResponse {Body = "{\"message\":\"pretty message\"}"}; + var expectedMessage = $"An error occurred with this API request: {apiResponse.Body}"; + var ctor = apiErrorExceptionType.GetConstructor(new[] {typeof(IApiResponse)}); + + var actualException = ctor.Invoke(new object[] {apiResponse}) as ApiErrorException; + + Assert.AreEqual(expectedMessage, actualException.Message); + } + } +} diff --git a/tests/GogoKit.Tests/GogoKit.Tests.csproj b/tests/GogoKit.Tests/GogoKit.Tests.csproj index 773f53e..5d6bf0c 100644 --- a/tests/GogoKit.Tests/GogoKit.Tests.csproj +++ b/tests/GogoKit.Tests/GogoKit.Tests.csproj @@ -71,6 +71,7 @@ + From a3cb1af684cbfa0e7c213d7c819cddfd70f712fb Mon Sep 17 00:00:00 2001 From: Akil Burgess Date: Tue, 15 Dec 2015 14:54:20 +0000 Subject: [PATCH 2/2] Add PurchasePreview.ConfirmLink * Added `purchasepreview:confirm` link to PurchasePreview resource * Added confirm callback url properties to NewPurchasePreview --- ReleaseNotes.md | 6 +++++- SolutionInfo.cs | 8 ++++---- src/GogoKit/Models/Request/NewPurchasePreview.cs | 6 ++++++ src/GogoKit/Models/Response/PurchasePreview.cs | 3 +++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 498dbfb..4b7d956 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,4 +1,8 @@ -### New in 0.5.0 (Releases 2015/11/23) +### New in 0.6.0 (Released 2015/12/15) +* ApiException.Message now returns actual error information from the API +* `purchasepreview:confirm` link added to PurchasePreview resource + +### New in 0.5.0 (Released 2015/11/23) * BearerAuthenticationHandler gets a `client_credentials` token automatically if the token store doesn't have a token yet diff --git a/SolutionInfo.cs b/SolutionInfo.cs index 71b983a..98858e3 100644 --- a/SolutionInfo.cs +++ b/SolutionInfo.cs @@ -5,12 +5,12 @@ [assembly: AssemblyProductAttribute("GogoKit")] [assembly: AssemblyCompanyAttribute("viagogo")] [assembly: AssemblyCopyrightAttribute("Copyright viagogo 2015")] -[assembly: AssemblyVersionAttribute("0.5.0")] -[assembly: AssemblyFileVersionAttribute("0.5.0")] -[assembly: AssemblyInformationalVersionAttribute("0.5.0")] +[assembly: AssemblyVersionAttribute("0.6.0")] +[assembly: AssemblyFileVersionAttribute("0.6.0")] +[assembly: AssemblyInformationalVersionAttribute("0.6.0")] [assembly: ComVisibleAttribute(false)] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "0.5.0"; + internal const string Version = "0.6.0"; } } diff --git a/src/GogoKit/Models/Request/NewPurchasePreview.cs b/src/GogoKit/Models/Request/NewPurchasePreview.cs index 03dde01..c57acbe 100644 --- a/src/GogoKit/Models/Request/NewPurchasePreview.cs +++ b/src/GogoKit/Models/Request/NewPurchasePreview.cs @@ -28,5 +28,11 @@ public class NewPurchasePreview [DataMember(Name = "coupons")] public string[] Coupons { get; set; } + + [DataMember(Name = "confirm_complete_callback")] + public string ConfirmCompleteCallbackUrl { get; set; } + + [DataMember(Name = "confirm_cancelled_callback")] + public string ConfirmCancelledCallbackUrl { get; set; } } } diff --git a/src/GogoKit/Models/Response/PurchasePreview.cs b/src/GogoKit/Models/Response/PurchasePreview.cs index 98279e6..5a45147 100644 --- a/src/GogoKit/Models/Response/PurchasePreview.cs +++ b/src/GogoKit/Models/Response/PurchasePreview.cs @@ -34,6 +34,9 @@ public class PurchasePreview : Resource [DataMember(Name = "estimated_total_charge")] public Money EstimatedTotalCharge { get; set; } + [Rel("purchasepreview:confirm")] + public Link ConfirmLink { get; set; } + [Rel("purchasepreview:createpurchase")] public Link CreatePurchaseLink { get; set; }