Amazon E-Commerce Service (ECS) provides specific and descriptive errors to help you troubleshoot problems with your requests. Each error consists of two components: an error code that identifies the error, and an error message that describes the error. In addition to describing what the error is and how it occurred, most error messages provide advice about how to correct the error. For a detailed list of error codes and messages, check the Error Codes and Messages section of the API Reference.
Error codes may appear at different levels within the XML response, depending on the operation and response groups used to generate the response. Each error is described by an Error element, and the individual Error elements occupy an Errors container element.
Errors that result from an invalid request appear at the top level of the response; in this case, the Errors element is a child of the root element of the response. An invalid request is one that ECS cannot run at all, such as a request that is missing the Service parameter.
Most errors appear at a deeper level of the response set. If an error is associated with a particular item (for example, a product, customer, or seller), the Error element is a descendent of that item in the response set. For example, an error associated with a specific product appears beneath the product's Item element.
If the error prevents retrieval of items, the Error element appears beneath the container that would normally hold such retrieved items. For example, a syntax error that prevents any products from being returned by an ItemSearch operation appears beneath the Items container element.
Typical Invalid Request Error
This response contains a top-level error in the Errors element.
<Errors> <Error> <Code>missing_service_parameter</Code> <Message> Your request is missing the Service parameter. Please add the Service parameter to your request and retry. Valid values for the Service parameter include AWSECommerceService. </Message> </Error> </Errors>
This is the invalid request that generated the error:
http://webservices.amazon.com/onca/xml?
Typical Error
This response contains an error at the Items level.
<ItemSearchResponse> <OperationRequest>
<HTTPHeaders> <Header Name="UserAgent"
Value="StandaloneModeUserAgent"/> </HTTPHeaders>
<RequestId>0E3CHSW8S5FCV3RHSTFS</RequestId> <Arguments>
<Argument Name="Service" Value="AWSECommerceService"/> <Argument
Name="AWSAccessKeyId" Value="[Your Access Key ID Here]"/> <Argument Name="Operation" Value="ItemSearch"/>
</Arguments> </OperationRequest> <Items> <Request>
<IsValid>False</IsValid> <Errors> <Error>
<Code>missing_parameters</Code> <Message> Your request is
missing required parameters. Required parameters include SearchIndex.
</Message> </Error> </Errors> </Request> </Items>
</ItemSearchResponse>
This is the request that generated the error:
http://webservices.amazon.com/onca/xml?Service=AWSECommerceService
&AWSAccessKeyId=[Your Access Key ID Here]
&Operation=ItemSearch
Often you will want your code to check whether or not a request generated an error before spending any time attempting to process results. The easiest way to find out if an error occurred is to look for an Error node in the response.
XPath Error Code Retrieval
XPath syntax provides a simple way to search for the presence of an Error node, as well as an easy way to retrive the error code and message. The following code snippet uses Perl and the XML::XPath module to determine if an error occurred during a request. If an error occurred, the code prints the first error code and message in the response.
use XML::XPath; my $xp = XML::XPath->new(xml =>
$response); if ( $xp->find("//Error") ) { print "There was an error
processing your request:\n", " Error code: ",
$xp->findvalue("//Error[1]/Code"), "\n", " ",
$xp->findvalue("//Error[1]/Message"), "\n\n"; }