aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2017-10-02 10:13:23 +0200
committerGitHub <[email protected]>2017-10-02 10:13:23 +0200
commitb18b6f201b75f704655e0784930a74050fb196b9 (patch)
tree26e0c87c04990806835920bbdce2042b0b1e1b67
parent15fe471df386a0a29a45d4e79ee1e3c4851aaac2 (diff)
parentc64617ee9474d8690df1e395f8454f02a0ddae6c (diff)
downloadmastodon.py-b18b6f201b75f704655e0784930a74050fb196b9.tar.gz
Merge pull request #89 from Elizafox/exception-hierarchy
Redesign exception hierarchy
-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 e59bdb7..5b198a5 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1263,21 +1263,29 @@ class Mastodon:
1263## 1263##
1264# Exceptions 1264# Exceptions
1265## 1265##
1266class MastodonIllegalArgumentError(ValueError): 1266class MastodonError(Exception):
1267 """Base class for Mastodon.py exceptions"""
1268
1269
1270class MastodonIllegalArgumentError(ValueError, MastodonError):
1267 pass 1271 pass
1268 1272
1269 1273
1270class MastodonFileNotFoundError(IOError): 1274class MastodonIOError(IOError, MastodonError):
1275 """Base class for Mastodon.py I/O errors"""
1276
1277
1278class MastodonFileNotFoundError(MastodonIOError):
1271 pass 1279 pass
1272 1280
1273 1281
1274class MastodonNetworkError(IOError): 1282class MastodonNetworkError(MastodonIOError):
1275 pass 1283 pass
1276 1284
1277 1285
1278class MastodonAPIError(Exception): 1286class MastodonAPIError(MastodonError):
1279 pass 1287 pass
1280 1288
1281 1289
1282class MastodonRatelimitError(Exception): 1290class MastodonRatelimitError(MastodonError):
1283 pass 1291 pass
Powered by cgit v1.2.3 (git 2.41.0)