-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logging to AmazonShipping providers and cleanup
Introduce logging capabilities in `AmazonShippingRateProvider` and `AmazonShippingShipmentProvider` for improved error handling. Log detailed error messages from the Amazon Shipping API. Remove redundant `services.AddLogging()` calls in `AddRestApiAmazonRateProvider` and `AddRestApiAmazonShipmentProvider`.
- Loading branch information
Brandon Moffett
committed
Dec 16, 2024
1 parent
be68694
commit c000fbc
Showing
4 changed files
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,24 @@ | |
using EasyKeys.Shipping.Amazon.Abstractions.Options; | ||
using EasyKeys.Shipping.Amazon.Abstractions.Services; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
namespace EasyKeys.Shipping.Amazon.Rates; | ||
|
||
public class AmazonShippingRateProvider : IAmazonShippingRateProvider | ||
{ | ||
private readonly IAmazonApiAuthenticatorService _authenticatorService; | ||
private readonly AmazonShippingApiOptions _options; | ||
private readonly AmazonShippingApi _shippingApi; | ||
private readonly ILogger<AmazonShippingRateProvider> _logger; | ||
|
||
public AmazonShippingRateProvider( | ||
ILogger<AmazonShippingRateProvider> logger, | ||
AmazonShippingApiOptions options, | ||
IAmazonApiAuthenticatorService authenticatorService, | ||
AmazonShippingApi shippingApi) | ||
{ | ||
_logger = logger; | ||
_options = options; | ||
_authenticatorService = authenticatorService; | ||
_shippingApi = shippingApi; | ||
|
@@ -121,14 +126,18 @@ public async Task<Shipment> GetRatesAsync(Shipment shipment, CancellationToken c | |
{ | ||
shipment.InternalErrors.Add(error.Message); | ||
} | ||
|
||
_logger.LogError(ex, $"Error getting rates from Amazon Shipping API: {string.Join(",",ex.Result.Errors)}"); | ||
Check warning on line 130 in src/EasyKeys.Shipping.Amazon.Rates/AmazonShippingRateProvider.cs
|
||
} | ||
catch (ApiException ex) | ||
{ | ||
shipment.InternalErrors.Add(ex.Message); | ||
_logger.LogError(ex, $"Error getting rates from Amazon Shipping API: {ex.Message}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
shipment.InternalErrors.Add(ex.Message); | ||
_logger.LogError(ex, $"Error getting rates from Amazon Shipping API: {ex.Message}"); | ||
} | ||
|
||
return shipment; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters