|
1 |
| -using FikaAmazonAPI.Services; |
| 1 | +using FikaAmazonAPI.AmazonSpApiSDK.Models.Exceptions; |
| 2 | +using FikaAmazonAPI.Services; |
2 | 3 | using FikaAmazonAPI.Utils;
|
3 | 4 | using System;
|
4 | 5 |
|
@@ -99,6 +100,8 @@ private void Authenticate(AmazonCredential Credentials)
|
99 | 100 |
|
100 | 101 | private void Init(AmazonCredential Credentials)
|
101 | 102 | {
|
| 103 | + ValidateCredentials(Credentials); |
| 104 | + |
102 | 105 | this.Credentials = Credentials;
|
103 | 106 |
|
104 | 107 | this._Authorization = new AuthorizationService(this.Credentials);
|
@@ -137,7 +140,25 @@ private void Init(AmazonCredential Credentials)
|
137 | 140 | this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials);
|
138 | 141 | this._VendorOrders = new VendorOrderService(this.Credentials);
|
139 | 142 | }
|
140 |
| - |
| 143 | + private void ValidateCredentials(AmazonCredential Credentials) |
| 144 | + { |
| 145 | + if (Credentials == null) |
| 146 | + throw new AmazonUnauthorizedException($"Error, you cannot make calls to Amazon without credentials!"); |
| 147 | + else if (string.IsNullOrEmpty(Credentials.AccessKey)) |
| 148 | + throw new AmazonInvalidInputException($"InvalidInput, AccessKey cannot be empty!"); |
| 149 | + else if (string.IsNullOrEmpty(Credentials.SecretKey)) |
| 150 | + throw new AmazonInvalidInputException($"InvalidInput, SecretKey cannot be empty!"); |
| 151 | + else if (string.IsNullOrEmpty(Credentials.RoleArn)) |
| 152 | + throw new AmazonInvalidInputException($"InvalidInput, RoleArn cannot be empty!"); |
| 153 | + else if (string.IsNullOrEmpty(Credentials.ClientId)) |
| 154 | + throw new AmazonInvalidInputException($"InvalidInput, ClientId cannot be empty!"); |
| 155 | + else if (string.IsNullOrEmpty(Credentials.ClientSecret)) |
| 156 | + throw new AmazonInvalidInputException($"InvalidInput, ClientSecret cannot be empty!"); |
| 157 | + else if (string.IsNullOrEmpty(Credentials.RefreshToken)) |
| 158 | + throw new AmazonInvalidInputException($"InvalidInput, RefreshToken cannot be empty!"); |
| 159 | + else if (Credentials.MarketPlace == null) |
| 160 | + throw new AmazonInvalidInputException($"InvalidInput, MarketPlace cannot be null!"); |
| 161 | + } |
141 | 162 | public MarketPlace GetCurrentMarketplace { get { return Credentials.MarketPlace; } }
|
142 | 163 | }
|
143 | 164 | }
|
0 commit comments