Responses & Errors
googleSheetsLib.models.Response
dataclass
Bases: Generic[T]
Universal response wrapper for all library operations.
This class uses Generics (T) to allow type checkers to understand the
structure of the returned data.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
T
|
The payload returned by the operation (e.g., a Sheet object,
a dictionary of values, or a list). Is |
error |
SheetsError
|
An error object containing details if the operation failed. |
ok |
bool
|
Success flag. Returns |
date |
datetime
|
Timestamp of when the response object was created. |
details |
Any
|
Extra metadata or debugging info regarding the request execution. Generally structured like a dcitionary with the request's information. |
Source code in src/googleSheetsLib/models.py
fail(message, code=None, function_name=None, details=None)
classmethod
Factory method to create a failure response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Description of what went wrong. |
required |
code
|
int
|
Error code associated with the failure. |
None
|
function_name
|
str
|
Context of where the error originated. |
None
|
details
|
Any
|
Raw exception or error data. |
None
|
Returns:
| Type | Description |
|---|---|
Response[Any]
|
Response[Any]: A response object with |
Source code in src/googleSheetsLib/models.py
success(data=None, details=None)
classmethod
Factory method to create a successful response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
T
|
The result of the operation. |
None
|
details
|
Any
|
Additional metadata. |
None
|
Returns:
| Type | Description |
|---|---|
Response[T]
|
Response[T]: A response object with |
Source code in src/googleSheetsLib/models.py
googleSheetsLib.models.SheetsError
dataclass
Standardized error container for API or library exceptions.
This class encapsulates error details to provide a consistent error handling experience across the library.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
A human-readable description of the error. |
code |
int
|
The HTTP status code (e.g., 404, 500) or internal error code. |
reason |
str
|
The API error reason (e.g., 'invalid_grant', 'notFound'). |
function_name |
str
|
The name of the method/function where the error occurred. Useful for debugging the call stack. |
details |
Any
|
Raw error payload or traceback information. |