Merge pull request #89 from Elizafox/exception-hierarchy
Redesign exception hierarchy
This commit is contained in:
commit
b18b6f201b
S'han modificat 2 arxius amb 19 adicions i 6 eliminacions
|
@ -112,12 +112,17 @@ Error handling
|
||||||
When Mastodon.py encounters an error, it will raise an exception, generally with
|
When Mastodon.py encounters an error, it will raise an exception, generally with
|
||||||
some text included to tell you what went wrong.
|
some text included to tell you what went wrong.
|
||||||
|
|
||||||
|
The base class that all mastodon exceptions inherit from is the MastodonError
|
||||||
|
class. If you are only interested in the fact an error was raised somewhere in
|
||||||
|
Mastodon.py, and not the details, this is the exception you can catch.
|
||||||
|
|
||||||
MastodonIllegalArgumentError is generally a programming problem - you asked the
|
MastodonIllegalArgumentError is generally a programming problem - you asked the
|
||||||
API to do something obviously invalid (i.e. specify a privacy scope that does
|
API to do something obviously invalid (i.e. specify a privacy scope that does
|
||||||
not exist).
|
not exist).
|
||||||
|
|
||||||
MastodonFileNotFoundError and MastodonNetworkError are IO errors - could be you
|
MastodonFileNotFoundError and MastodonNetworkError are IO errors - could be you
|
||||||
specified a wrong URL, could be the internet is down or your hard drive is dying.
|
specified a wrong URL, could be the internet is down or your hard drive is
|
||||||
|
dying. They inherit from MastodonIOError, for easy catching.
|
||||||
|
|
||||||
MastodonAPIError is an error returned from the Mastodon instance - the server
|
MastodonAPIError is an error returned from the Mastodon instance - the server
|
||||||
has decided it can't fullfill your request (i.e. you requested info on a user that
|
has decided it can't fullfill your request (i.e. you requested info on a user that
|
||||||
|
|
|
@ -1263,21 +1263,29 @@ class Mastodon:
|
||||||
##
|
##
|
||||||
# Exceptions
|
# Exceptions
|
||||||
##
|
##
|
||||||
class MastodonIllegalArgumentError(ValueError):
|
class MastodonError(Exception):
|
||||||
|
"""Base class for Mastodon.py exceptions"""
|
||||||
|
|
||||||
|
|
||||||
|
class MastodonIllegalArgumentError(ValueError, MastodonError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MastodonFileNotFoundError(IOError):
|
class MastodonIOError(IOError, MastodonError):
|
||||||
|
"""Base class for Mastodon.py I/O errors"""
|
||||||
|
|
||||||
|
|
||||||
|
class MastodonFileNotFoundError(MastodonIOError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MastodonNetworkError(IOError):
|
class MastodonNetworkError(MastodonIOError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MastodonAPIError(Exception):
|
class MastodonAPIError(MastodonError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MastodonRatelimitError(Exception):
|
class MastodonRatelimitError(MastodonError):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Referencia en una nova incidència