Skip to content

Commit 88791c7

Browse files
added amazon invalidinput exception
1 parent c018997 commit 88791c7

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public AmazonUnauthorizedException(string msg, IRestResponse response = null) :
3636
}
3737
}
3838

39+
public class AmazonInvalidInputException : AmazonException
40+
{
41+
public AmazonInvalidInputException(string msg, IRestResponse response = null) : base(msg, response)
42+
{
43+
44+
}
45+
}
46+
3947
public class ExceptionResponse
4048
{
4149
public string Content { get; set; }

Source/FikaAmazonAPI/Services/RequestService.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,20 @@ protected void ParseResponse(IRestResponse response)
162162
if (response.StatusCode == HttpStatusCode.Forbidden)
163163
{
164164
var error = response.Content.ConvertToErrorResponse();
165-
if (error != null && error.Errors.Any(x => x.Code == HttpStatusCode.Unauthorized))
165+
if (error != null && error.Errors.Any(x => x.Code.Equals("Unauthorized")))
166166
{
167167
throw new AmazonUnauthorizedException("Access to requested resource is denied.", response);
168168
}
169169
}
170-
170+
if (response.StatusCode == HttpStatusCode.BadRequest)
171+
{
172+
var error = response.Content.ConvertToErrorResponse();
173+
if (error != null && error.Errors.Any(x => x.Code.Equals("InvalidInput")))
174+
{
175+
throw new AmazonInvalidInputException("Invalid input found", response);
176+
}
177+
}
178+
171179
Console.WriteLine("Amazon Api didn't respond with Okay, see exception for more details" + response.Content);
172180
throw new AmazonException("Amazon Api didn't respond with Okay, see exception for more details", response);
173181
}

Source/FikaAmazonAPI/Utils/ErrorResponseHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ErrorResponseElement
3333
[JsonProperty("message")]
3434
public string Message { get; set; }
3535
[JsonProperty("code")]
36-
public HttpStatusCode Code { get; set; }
36+
public string Code { get; set; }
3737
[JsonProperty("details")]
3838
public string Details { get; set; }
3939
}

0 commit comments

Comments
 (0)