Exceptions¶
All library exceptions derive from
MregApiBaseError. API errors
(APIError and subclasses) carry the originating HTTP
response and expose parsed error details.
exceptions
¶
Exception classes for MREG API errors.
APIError
¶
Bases: MregApiBaseError
Exception class for API errors.
Parses drf-standardized-errors errors from the MREG API if present in response.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
CacheError
¶
Bases: MregApiBaseError
Error related to caching.
CacheMiss
¶
Bases: CacheError
Cache miss error.
DeleteError
¶
Bases: APIError
Error class for failed deletion.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
EntityAlreadyExists
¶
Bases: MregApiBaseError
Entity already exists when none was expected.
EntityNotFound
¶
Bases: MregApiBaseError
No entity found when at least one was expected.
EntityOwnershipMismatch
¶
Bases: MregApiBaseError
Entity already exists but is owned by someone else.
ForceMissing
¶
Bases: MregApiBaseError
Error class for missing force flag.
GetError
¶
Bases: APIError
Error class for failed retrieval.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
IPNetworkError
¶
Bases: ValueError, MregApiBaseError
Error class for IP network/address errors.
InputFailure
¶
Bases: MregApiBaseError, ValueError
Error class for input failure.
InternalError
¶
Bases: MregApiBaseError
Error class for internal errors.
InvalidAuthTokenError
¶
Bases: LoginFailedError
Invalid authentication token.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
InvalidIPAddress
¶
Bases: IPNetworkError
Entity is not a valid IP address.
InvalidIPv4Address
¶
Bases: IPNetworkError
Entity is not a valid IPv4 address.
InvalidIPv6Address
¶
Bases: IPNetworkError
Entity is not a valid IPv6 address.
InvalidNetwork
¶
Bases: IPNetworkError
Entity is not a valid network.
LoginFailedError
¶
Bases: APIError
Login failed.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
MREGError
pydantic-model
¶
Bases: BaseModel
Details of an MREG error.
Show JSON schema:
{
"description": "Details of an MREG error.",
"properties": {
"code": {
"title": "Code",
"type": "string"
},
"detail": {
"title": "Detail",
"type": "string"
},
"attr": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Attr"
}
},
"required": [
"code",
"detail",
"attr"
],
"title": "MREGError",
"type": "object"
}
Fields:
MREGErrorResponse
pydantic-model
¶
Bases: BaseModel
MREG error response.
Show JSON schema:
{
"$defs": {
"MREGError": {
"description": "Details of an MREG error.",
"properties": {
"code": {
"title": "Code",
"type": "string"
},
"detail": {
"title": "Detail",
"type": "string"
},
"attr": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Attr"
}
},
"required": [
"code",
"detail",
"attr"
],
"title": "MREGError",
"type": "object"
}
},
"description": "MREG error response.",
"properties": {
"type": {
"title": "Type",
"type": "string"
},
"errors": {
"default": [],
"items": {
"$ref": "#/$defs/MREGError"
},
"title": "Errors",
"type": "array"
}
},
"required": [
"type"
],
"title": "MREGErrorResponse",
"type": "object"
}
Fields:
MregValidationError
¶
Bases: MregApiBaseError
Validation error class for MREG API.
Stems from Pydantic ValidationError but adds context about the API request that caused the validation to fail.
__init__
¶
__init__(
message: str,
pydantic_error: ValidationError | None = None,
)
Initialize an MregValidationError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The error message. |
required |
pydantic_error
|
ValidationError | None
|
The Pydantic validation error, if any. |
None
|
from_pydantic
classmethod
¶
from_pydantic(
e: ValidationError, context: str | None = None
) -> MregValidationError
Create an MregValidationError from a Pydantic MregValidationError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
ValidationError
|
The Pydantic MregValidationError. |
required |
context
|
str | None
|
What was being validated (e.g., "JSON", "string", "object"). |
None
|
Returns:
| Type | Description |
|---|---|
MregValidationError
|
The created MregValidationError. |
MultipleEntitiesFound
¶
Bases: MregApiBaseError
Multiple entities found when only one was expected.
PatchError
¶
Bases: APIError
Error class for failed patching.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
PostError
¶
Bases: APIError
Error class for failed creation.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
TooManyResults
¶
Bases: MregApiBaseError
API returned too many results.
UnexpectedDataError
¶
Bases: APIError
Error class for unexpected API data.
detail
cached
property
¶
detail: str
Clean human-readable error message from the response.
Joins the detail of each parsed error with "; ". Empty if the response has no parseable errors.
errors
cached
property
¶
errors: MREGErrorResponse
Get the parsed MREG errors from the response.
Returns:
| Type | Description |
|---|---|
MREGErrorResponse
|
The MREGErrorResponse object, or a default MREGErrorResponse with type "unknown" if the response |
request
property
¶
Get the request that triggered the exception.
Uses the request from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Request | None
|
The request object or None if not set. |
response
property
¶
Get the response object associated with the error.
Uses the response from the cause if not set directly.
Returns:
| Type | Description |
|---|---|
Response | None
|
The response object or None if not set. |
status_code
property
¶
status_code: int | None
Get the HTTP status code of the response, if available.
__init__
¶
__init__(
message: str = "", response: Response | None = None
)
Initialize an APIError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message override. When empty, the message is
derived from the response (parsed error details, then raw text,
then reason phrase) via |
''
|
response
|
Response | None
|
The response object that triggered the exception. |
None
|
formatted_message
¶
determine_http_error_class
¶
fmt_error_code
¶
parse_mreg_error
¶
parse_mreg_error(
resp: Response,
) -> MREGErrorResponse | None
Parse an MREG error response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resp
|
Response
|
The response object to parse. |
required |
Returns:
| Type | Description |
|---|---|
MREGErrorResponse | None
|
A MREGErrorResponse object or None if it cannot be parsed. |