Skip to content

Commit 2ad625e

Browse files
committed
fix #435
1 parent 41e52c2 commit 2ad625e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Source/FikaAmazonAPI/AmazonConnection.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FikaAmazonAPI.Services;
1+
using FikaAmazonAPI.AmazonSpApiSDK.Models.Exceptions;
2+
using FikaAmazonAPI.Services;
23
using FikaAmazonAPI.Utils;
34
using System;
45

@@ -99,6 +100,8 @@ private void Authenticate(AmazonCredential Credentials)
99100

100101
private void Init(AmazonCredential Credentials)
101102
{
103+
ValidateCredentials(Credentials);
104+
102105
this.Credentials = Credentials;
103106

104107
this._Authorization = new AuthorizationService(this.Credentials);
@@ -137,7 +140,25 @@ private void Init(AmazonCredential Credentials)
137140
this._VendorDirectFulfillmentOrders = new VendorDirectFulfillmentOrderService(this.Credentials);
138141
this._VendorOrders = new VendorOrderService(this.Credentials);
139142
}
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+
}
141162
public MarketPlace GetCurrentMarketplace { get { return Credentials.MarketPlace; } }
142163
}
143164
}

0 commit comments

Comments
 (0)