mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
1.4 KiB
1.4 KiB
Error Handling
Good error handling is the difference between a stable integration and random production failures.
Exception hierarchy
FragmentErrorClientErrorConfigurationErrorCookieError
FragmentAPIErrorFragmentPageErrorUserNotFoundErrorAnonymousNumberErrorTransactionErrorParseErrorVerificationError
OperationErrorWalletErrorUnexpectedError
Recommended handling pattern
from pyfragment import ConfigurationError, FragmentError, UserNotFoundError, WalletError
try:
result = await client.purchase_stars("@username", amount=500)
except UserNotFoundError:
# recipient does not exist on Fragment
...
except WalletError:
# insufficient balance or wallet-side issue
...
except ConfigurationError:
# invalid local input
...
except FragmentError:
# any other library-level failure
...
Catch specific errors first, then fallback to FragmentError.
Method-to-error mapping
- Stars/Premium purchase and giveaway:
ConfigurationError,UserNotFoundError,WalletError,VerificationError - Ads operations:
ConfigurationError,UserNotFoundError,WalletError,VerificationError - Cookies/auth setup:
CookieError,ConfigurationError,FragmentPageError
Canonical messages
See pyfragment/exceptions.py for source-of-truth message templates.