aboutsummaryrefslogtreecommitdiffstats
path: root/src/IOL.VippsEcommerce/VippsEcommerceService.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2021-04-02 14:51:33 +0200
committerivarlovlie <git@ivarlovlie.no>2021-04-02 14:51:33 +0200
commit78f6e40f0df706a18fa3489e8cce9c36de55859f (patch)
treeb7bd326270b06b0dd4daf354e8a7de68f0df4f68 /src/IOL.VippsEcommerce/VippsEcommerceService.cs
parent9c440d7aa4a776be9051489a40944d779d032d96 (diff)
downloaddotnet-vipps-ecommerce-78f6e40f0df706a18fa3489e8cce9c36de55859f.tar.xz
dotnet-vipps-ecommerce-78f6e40f0df706a18fa3489e8cce9c36de55859f.zip
throw on unsuccessful response when requesting tokens
Diffstat (limited to 'src/IOL.VippsEcommerce/VippsEcommerceService.cs')
-rw-r--r--src/IOL.VippsEcommerce/VippsEcommerceService.cs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/IOL.VippsEcommerce/VippsEcommerceService.cs b/src/IOL.VippsEcommerce/VippsEcommerceService.cs
index 54e68a6..1611809 100644
--- a/src/IOL.VippsEcommerce/VippsEcommerceService.cs
+++ b/src/IOL.VippsEcommerce/VippsEcommerceService.cs
@@ -92,7 +92,7 @@ namespace IOL.VippsEcommerce
}
}
- _logger.LogInformation("VippsEcommerceService was initialized with api url: " + vippsApiUrl);
+ _logger.LogInformation("VippsEcommerceService was successfully initialised with api url: " + vippsApiUrl);
}
/// <summary>
@@ -165,8 +165,21 @@ namespace IOL.VippsEcommerce
_logger.LogDebug("VippsEcommerceService: Got tokens from " + requestMessage.RequestUri);
return JsonSerializer.Deserialize<VippsAuthorizationTokenResponse>(credentials);
} catch (Exception e) {
+ var exception =
+ new VippsRequestException("Vipps get token request returned unsuccessfully.", e);
+ if (e is HttpRequestException) {
+ try {
+ exception.ErrorResponse =
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ _logger.LogError("ErrorResponse: " + JsonSerializer.Serialize(response.Content));
+ } catch (Exception e1) {
+ _logger.LogError("Unknown ErrorResponse: " + JsonSerializer.Serialize(response.Content));
+ Console.WriteLine(e1);
+ }
+ }
+
Console.WriteLine(e);
- return default;
+ throw exception;
}
}