Exceptions API
The exceptions module provides custom exceptions for the USDA FDC client.
FdcApiError
FdcAuthError
- class usda_fdc.exceptions.FdcAuthError(message, status_code=None)[source]
Bases:
FdcApiErrorException raised when authentication fails.
api.data.gov, which fronts FDC, answers an invalid or missing key with 403 rather than 401, so both statuses raise this.
FdcRateLimitError
- class usda_fdc.exceptions.FdcRateLimitError(message, status_code=None)[source]
Bases:
FdcApiErrorException raised when the API rate limit is exceeded.
FdcTimeoutError
- class usda_fdc.exceptions.FdcTimeoutError(message, status_code=None)[source]
Bases:
FdcApiErrorException raised when a request to the FDC API times out.
Distinct from a generic FdcApiError so callers can tell “slow” from “broken” — a timeout is usually worth retrying, a 400 is not.
FdcValidationError
- class usda_fdc.exceptions.FdcValidationError(message, status_code=None)[source]
Bases:
FdcApiErrorException raised when the API rejects the request as invalid (HTTP 400).
Typically a parameter outside the range FDC accepts, such as a page_size above 200.
FdcResourceNotFoundError
- class usda_fdc.exceptions.FdcResourceNotFoundError(message, status_code=None)[source]
Bases:
FdcApiErrorException raised when a requested resource is not found (HTTP 404).
A food that does not exist is an ordinary outcome of a lookup, not a breakdown, so callers deserve to catch it on its own.