diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2021-04-02 14:51:33 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2021-04-02 14:51:33 +0200 |
| commit | 78f6e40f0df706a18fa3489e8cce9c36de55859f (patch) | |
| tree | b7bd326270b06b0dd4daf354e8a7de68f0df4f68 /src/IOL.VippsEcommerce/VippsEcommerceService.cs | |
| parent | 9c440d7aa4a776be9051489a40944d779d032d96 (diff) | |
| download | dotnet-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.cs | 17 |
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; } } |
