aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/errors.py15
-rw-r--r--discord/utils.py9
-rw-r--r--docs/api.rst4
3 files changed, 26 insertions, 2 deletions
diff --git a/discord/errors.py b/discord/errors.py
index 0d75fb53..e943ee13 100644
--- a/discord/errors.py
+++ b/discord/errors.py
@@ -65,6 +65,21 @@ class HTTPException(DiscordException):
super().__init__(fmt.format(self.response, message))
+class Forbidden(HTTPException):
+ """Exception that's thrown for when status code 403 occurs.
+
+ Subclass of :exc:`HTTPException`
+ """
+ pass
+
+class NotFound(HTTPException):
+ """Exception that's thrown for when status code 404 occurs.
+
+ Subclass of :exc:`HTTPException`
+ """
+ pass
+
+
class InvalidArgument(ClientException):
"""Exception that's thrown when an argument to a function
is invalid some way (e.g. wrong value or wrong type).
diff --git a/discord/utils.py b/discord/utils.py
index 3e22c710..d2477696 100644
--- a/discord/utils.py
+++ b/discord/utils.py
@@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE.
"""
from re import split as re_split
-from .errors import HTTPException, InvalidArgument
+from .errors import HTTPException, Forbidden, NotFound, InvalidArgument
import datetime
import asyncio
@@ -66,7 +66,12 @@ def _verify_successful_response(response):
success = code >= 200 and code < 300
if not success:
data = yield from response.json()
- raise HTTPException(response, data.get('message'))
+ message = data.get('message')
+ if code == 403:
+ raise Forbidden(response, message)
+ elif code == 404:
+ raise NotFound(response, message)
+ raise HTTPException(response, message)
def _get_mime_type_for_image(data):
if data.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'):
diff --git a/docs/api.rst b/docs/api.rst
index 1e0bdd62..f9853b6d 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -358,6 +358,10 @@ The following exceptions are thrown by the library.
.. autoexception:: HTTPException
:members:
+.. autoexception:: Forbidden
+
+.. autoexception:: NotFound
+
.. autoexception:: InvalidArgument
.. autoexception:: GatewayNotFound