aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Myers <[email protected]>2017-09-25 19:05:12 -0500
committerElizabeth Myers <[email protected]>2017-09-25 19:11:16 -0500
commitc64617ee9474d8690df1e395f8454f02a0ddae6c (patch)
tree390cfd966da48c08dae404889180303be5f93429
parent6ab283d17e1eac2b521bbaffc1b0a635fd68c9f5 (diff)
downloadmastodon.py-c64617ee9474d8690df1e395f8454f02a0ddae6c.tar.gz
Redesign exception hierarchy
All Mastodon.py errors now derive from MastodonError, for easier catching in application code that just wants to see if something happened, and isn't too miffed about the details. I/O Errors derive from MastodonIOError, for similar reasons. This change is designed to be backwards compatible.
-rw-r--r--docs/index.rst7
-rw-r--r--mastodon/Mastodon.py18
2 files changed, 19 insertions, 6 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 11b655a..fae8b2d 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -112,12 +112,17 @@ Error handling
112When Mastodon.py encounters an error, it will raise an exception, generally with 112When Mastodon.py encounters an error, it will raise an exception, generally with
113some text included to tell you what went wrong. 113some text included to tell you what went wrong.
114 114
115The base class that all mastodon exceptions inherit from is the MastodonError
116class. If you are only interested in the fact an error was raised somewhere in
117Mastodon.py, and not the details, this is the exception you can catch.
118
115MastodonIllegalArgumentError is generally a programming problem - you asked the 119MastodonIllegalArgumentError is generally a programming problem - you asked the
116API to do something obviously invalid (i.e. specify a privacy scope that does 120API to do something obviously invalid (i.e. specify a privacy scope that does
117not exist). 121not exist).
118 122
119MastodonFileNotFoundError and MastodonNetworkError are IO errors - could be you 123MastodonFileNotFoundError and MastodonNetworkError are IO errors - could be you
120specified a wrong URL, could be the internet is down or your hard drive is dying. 124specified a wrong URL, could be the internet is down or your hard drive is
125dying. They inherit from MastodonIOError, for easy catching.
121 126
122MastodonAPIError is an error returned from the Mastodon instance - the server 127MastodonAPIError is an error returned from the Mastodon instance - the server
123has decided it can't fullfill your request (i.e. you requested info on a user that 128has decided it can't fullfill your request (i.e. you requested info on a user that
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 49db771..8634fd1 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1280,21 +1280,29 @@ class Mastodon:
1280## 1280##
1281# Exceptions 1281# Exceptions
1282## 1282##
1283class MastodonIllegalArgumentError(ValueError): 1283class MastodonError(Exception):
1284 """Base class for Mastodon.py exceptions"""
1285
1286
1287class MastodonIllegalArgumentError(ValueError, MastodonError):
1284 pass 1288 pass
1285 1289
1286 1290
1287class MastodonFileNotFoundError(IOError): 1291class MastodonIOError(IOError, MastodonError):
1292 """Base class for Mastodon.py I/O errors"""
1293
1294
1295class MastodonFileNotFoundError(MastodonIOError):
1288 pass 1296 pass
1289 1297
1290 1298
1291class MastodonNetworkError(IOError): 1299class MastodonNetworkError(MastodonIOError):
1292 pass 1300 pass
1293 1301
1294 1302
1295class MastodonAPIError(Exception): 1303class MastodonAPIError(MastodonError):
1296 pass 1304 pass
1297 1305
1298 1306
1299class MastodonRatelimitError(Exception): 1307class MastodonRatelimitError(MastodonError):
1300 pass 1308 pass
Powered by cgit v1.2.3 (git 2.41.0)