Repository URL to install this package:
|
Version:
8.0.0 ▾
|
from zeep import exceptions
from sincpro_siat_soap.exceptions import (
SincproAuthError,
SincproExternalServiceError,
SincproServiceUnavailableError,
)
from sincpro_siat_soap.logger import logger
_AUTH_FAULT_KEYWORDS = ("api key", "apikey", "no valido", "token", "unauthorized", "401")
def siat_global_error_handler(error: Exception) -> None:
"""Map zeep errors to Sincpro SDK exceptions so callers get a consistent exception type."""
if isinstance(error, exceptions.Fault):
message = error.message or ""
if any(kw in message.lower() for kw in _AUTH_FAULT_KEYWORDS):
logger.error(f"SIAT authentication error: {message}", alert=True)
raise SincproAuthError(f"SIAT authentication error: {message}") from error
raise SincproExternalServiceError(f"SIAT SOAP Fault: {message}") from error
if isinstance(error, exceptions.TransportError):
raise SincproServiceUnavailableError(
f"SIAT service unreachable (HTTP {error.status_code})"
) from error
raise error