AMSError#

class teamworksams.utils.AMSError(message: str, function: str | None = None, endpoint: str | None = None, status_code: int | None = None)[source]#

Bases: Exception

Base exception for AMS operations and errors.

Raised for errors during AMS API interactions, such as authentication failures or invalid responses. Provides detailed error information, including function, endpoint, and HTTP status code, to aid debugging. Used by functions like get_client() and login().

Parameters:
  • message (str) – The primary error message describing the issue.

  • function (Optional[str]) – Name of the function where the error occurred (e.g., ‘login’). Defaults to None.

  • endpoint (Optional[str]) – API endpoint involved (e.g., ‘user/loginUser’). Defaults to None.

  • status_code (Optional[int]) – HTTP status code of the error (e.g., 401 for unauthorized). Defaults to None.

message#

The primary error message.

Type:

str

function#

The function where the error occurred.

Type:

Optional[str]

endpoint#

The API endpoint involved.

Type:

Optional[str]

status_code#

The HTTP status code.

Type:

Optional[int]

Examples

>>> try:
...     raise AMSError(
...         message="Invalid credentials",
...         function="login",
...         endpoint="user/loginUser",
...         status_code=401
...     )
... except AMSError as e:
...     print(str(e))
Invalid credentials - Function: login - Endpoint: user/loginUser - Status Code: 401. Please check inputs or contact your site administrator.
__init__(message: str, function: str | None = None, endpoint: str | None = None, status_code: int | None = None)[source]#

Additional Notes#

  • The error message includes context like function name and endpoint, aiding debugging (e.g., “Invalid credentials - Function: login - Endpoint: user/loginUser”).

  • Raised by all teamworksams functions for consistent error handling, with interactive feedback when interactive_mode is enabled (e.g., in LoginOption()).

See Also#