Skip to content

Commit d53d900

Browse files
committed
Additional Error cases for API response
Handle internal error and BadRequest with no content https://developer-docs.amazon.com/sp-api/changelog/api-request-validation-for-400-errors-with-html-response
1 parent de1d9a0 commit d53d900

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,30 @@ public AmazonInvalidSignatureException(string msg, RestResponse response = null)
5959
}
6060
}
6161

62+
public class AmazonInternalErrorException : AmazonException
63+
{
64+
public AmazonInternalErrorException(string msg, RestResponse response = null) : base(msg, response)
65+
{
66+
67+
}
68+
}
69+
70+
public class AmazonBadRequestException : AmazonException
71+
{
72+
public AmazonBadRequestException(string msg, RestResponse response = null) : base(msg, response)
73+
{
74+
75+
}
76+
}
77+
6278
public class AmazonProcessingReportDeserializeException : AmazonException
6379
{
6480
public string ReportContent { get; set; }
6581
public AmazonProcessingReportDeserializeException(string msg, string reportContent, RestResponse response = null) : base(msg, response)
6682
{
6783
ReportContent = reportContent;
6884
}
69-
}
85+
}
7086

7187
public class ExceptionResponse
7288
{

Source/FikaAmazonAPI/Services/RequestService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FikaAmazonAPI.AmazonSpApiSDK.Models.Exceptions;
1+
using FikaAmazonAPI.AmazonSpApiSDK.Models.Exceptions;
22
using FikaAmazonAPI.AmazonSpApiSDK.Models.Filters;
33
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
44
using FikaAmazonAPI.AmazonSpApiSDK.Runtime;
@@ -286,11 +286,18 @@ protected void ParseResponse(RestResponse response)
286286
throw new AmazonInvalidInputException(error.Message, response);
287287
case "QuotaExceeded":
288288
throw new AmazonQuotaExceededException(error.Message, response);
289+
case "InternalFailure":
290+
throw new AmazonInternalErrorException(error.Message, response);
289291
}
290292

291293
}
292294
}
293295

296+
if (response.StatusCode == HttpStatusCode.BadRequest)
297+
{
298+
throw new AmazonBadRequestException("BadRequest see https://developer-docs.amazon.com/sp-api/changelog/api-request-validation-for-400-errors-with-html-response for advice", response);
299+
}
300+
294301
throw new AmazonException("Amazon Api didn't respond with Okay, see exception for more details", response);
295302
}
296303

0 commit comments

Comments
 (0)