Errors and rate limits

Errors

Any error status from S&S raises SSActivewearAPIError or one of its subclasses:

SSActivewearBadRequestError

HTTP 400. Part of the request was invalid.

SSActivewearNotFoundError

HTTP 404. None of the requested items exist, or they have been discontinued.

The exception carries the status code and, when the body was a recognizable error, the parsed ErrorResponse, which lists each problem:

from ssactivewear_sdk import SSActivewearBadRequestError

try:
    ss.create_order(order)
except SSActivewearBadRequestError as error:
    for detail in error.response.errors if error.response else []:
        print(detail.field, detail.message)

Every exception the SDK raises for an API error derives from SSActivewearError.

Rate limits

S&S allows 60 requests a minute. After each response, the client records how many are left in rate_limit_remaining. It is None until S&S has reported it:

import time

ss.get_categories()
if ss.rate_limit_remaining is not None and ss.rate_limit_remaining < 5:
    time.sleep(60)