UNPKG

@lorenstuff/amazon-selling-partner-api

Version:

A package for interacting with the Amazon Selling Partner API.

58 lines 2.38 kB
// // Class // /** An object representing an error returned by the Amazon Selling Partner API. */ export class AmazonSellingPartnerAPIError extends Error { /** * Gets the appropriate error message for the given status code. * * @param statusCode */ static getErrorMessage(statusCode) { switch (statusCode) { case 400: return "Request has missing or invalid parameters and cannot be parsed."; case 401: return "The request's Authorization header is not formatted correctly or does not contain a valid token."; case 403: return "Indicates access to the resource is forbidden. Possible reasons include Access Denied, Unauthorized, Expired Token, or Invalid Signature."; case 404: return "The specified resource does not exist."; case 413: return "The request size exceeded the maximum accepted size."; case 415: return "The request's Content-Type header is invalid."; case 429: return "The frequency of requests was greater than allowed."; case 500: return "An unexpected condition occurred that prevented the server from fulfilling the request."; case 503: return "Temporary overloading or maintenance of the server."; default: return "An unknown error occurred."; } } /** The status code of the response. */ statusCode; /** The x-amzn-RateLimit-Limit header of the response. */ rateLimit; /** The x-amzn-RequestId header of the response. */ requestId; /** The errors returned by the API. */ errors; /** * Constructs a new AmazonSellingPartnerAPIError. * * @param response A response from the Amazon Selling Partner API. * @param errors The errors returned by the API. */ constructor(response, errors) { const message = AmazonSellingPartnerAPIError.getErrorMessage(response.status); super(message); this.statusCode = response.status; this.rateLimit = response.headers.get("x-amzn-RateLimit-Limit"); this.requestId = response.headers.get("x-amzn-RequestId"); this.errors = errors; } } //# sourceMappingURL=AmazonSellingPartnerAPIError.js.map