Error Handling
All functions raise exceptions from the notifiedby.exceptions module when something goes wrong.
Exception Types
from notifiedby import subscribe_to_flow
from notifiedby.exceptions import (
NotifiedByError,
NotifiedByConfigError,
NotifiedByAPIError,
NotifiedByValidationError,
NotifiedByAuthError,
NotifiedByNotFoundError,
)
try:
subscribe_to_flow(
flow_trigger='WELCOME_SIGNUP',
email='user@example.com',
)
except NotifiedByConfigError:
# Missing API key in Django settings
print("Check your NOTIFIEDBY_API_KEY setting")
except NotifiedByValidationError as e:
# Bad request (400) - e.g. flow not found, already subscribed
print(f"Validation error: {e}")
except NotifiedByAuthError:
# Authentication failed (401/403)
print("Invalid API key or feature not enabled")
except NotifiedByNotFoundError:
# Resource not found (404)
print("Not found")
except NotifiedByAPIError as e:
# Other API error
print(f"API error ({e.status_code}): {e}")
except NotifiedByError:
# Network or other error
print("Something went wrong")
Exception Hierarchy
NotifiedByError– Base exception for all errors.NotifiedByConfigError– Missing or invalid configuration (e.g. no API key).NotifiedByAPIError– An error response from the API.NotifiedByValidationError– HTTP 400 (bad request).NotifiedByAuthError– HTTP 401 or 403 (authentication/authorisation failure).NotifiedByNotFoundError– HTTP 404 (resource not found).
Common Error Scenarios
Configuration Errors:
# Missing API key
NotifiedByConfigError: NOTIFIEDBY_API_KEY is not set in Django settings
Validation Errors:
# Invalid email address
NotifiedByValidationError: Enter a valid email address
# Flow not found
NotifiedByValidationError: Flow with trigger 'INVALID_FLOW' not found
Authentication Errors:
# Invalid API key
NotifiedByAuthError: Authentication failed
# Feature not enabled
NotifiedByAuthError: Email flows feature not enabled for this account
Network Errors:
# Connection timeout
NotifiedByError: Request failed: Connection timed out
# DNS resolution failure
NotifiedByError: Request failed: Name resolution failure