Exceptions
exceptions - Exception classes for USPTO API clients
This module provides exception classes for USPTO API errors that correspond to the various response types from the USPTO API. It also includes helper structures and functions for creating these exceptions.
- class pyUSPTO.exceptions.APIErrorArgs(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
objectData structure to hold arguments for API exception constructors.
- classmethod from_http_error(http_error, client_operation_message)[source]
Creates an APIErrorArgs instance by parsing a requests.exceptions.HTTPError.
- Parameters:
- Return type:
- Returns:
An instance of APIErrorArgs populated with details from the HTTPError.
- exception pyUSPTO.exceptions.USPTOApiAuthError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorAuthentication/Authorization error (HTTP 401/403).
- exception pyUSPTO.exceptions.USPTOApiBadRequestError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorBad Request error (HTTP 400).
- exception pyUSPTO.exceptions.USPTOApiError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
ExceptionBase exception for USPTO API errors. This is the parent class for all USPTO API-specific exceptions. It includes information about the status code, API’s short error message, detailed error information, and request identifier from the API response.
- DEFAULT_UNKNOWN_MESSAGE = 'UNK USPTO API ERROR'
- __init__(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Initializes the USPTOApiError. :type message:
str:param message: The primary message for the exception (often client-generated context). :type status_code:int|None:param status_code: The HTTP status code from the API response (e.g., 400, 403). :type api_short_error:str|None:param api_short_error: The short error description from the API (e.g., “Bad Request”, “Forbidden”). :type error_details:str|dict|None:param error_details: The detailed error message or structure from the API. :type request_identifier:str|None:param request_identifier: The request identifier from the API response, if available.
- exception pyUSPTO.exceptions.USPTOApiNotFoundError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorResource not found error (HTTP 404).
- exception pyUSPTO.exceptions.USPTOApiPayloadTooLargeError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorPayload Too Large error (HTTP 413).
- exception pyUSPTO.exceptions.USPTOApiRateLimitError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorRate limit exceeded error (HTTP 429).
- exception pyUSPTO.exceptions.USPTOApiServerError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorInternal Server Error (HTTP 500 series).
- exception pyUSPTO.exceptions.USPTOConnectionError(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorNetwork-level connection error (DNS failure, refused connection, etc.).
- exception pyUSPTO.exceptions.USPTOTimeout(message, status_code=None, api_short_error=None, error_details=None, request_identifier=None)[source]
Bases:
USPTOApiErrorRequest to USPTO API timed out.
- pyUSPTO.exceptions.get_api_exception(error_args)[source]
Determines and instantiates the appropriate USPTOApiError subclass based on the status code in error_args.
- Parameters:
error_args (
APIErrorArgs) – An instance of APIErrorArgs containing all necessary information to construct the exception.- Return type:
- Returns:
An instance of a USPTOApiError subclass.