Skip to content

Commit 4bdf9f4

Browse files
author
Emanuel Winblad
committed
Small changes to exception handling introducing additional exception classes.
1 parent 65e1923 commit 4bdf9f4

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

vilfo/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ def _request(self, method, endpoint, headers=None, data=None, params=None, timeo
4646
try:
4747
response = getattr(requests, method)(url, headers=headers, data=data, params=params, timeout=timeout)
4848
except requests.exceptions.RequestException as ex:
49-
raise ex
49+
# Wrap the exception in our own exception class.
50+
raise vilfo.exceptions.VilfoRequestException(ex)
5051

5152
if 404 == response.status_code:
52-
raise vilfo.exceptions.VilfoException()
53+
raise vilfo.exceptions.NotFoundException()
5354

5455
if 403 == response.status_code or response_content_is_login_page(response.content):
5556
raise vilfo.exceptions.AuthenticationException()

vilfo/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
"""The exceptions used by the Vilfo client."""
2+
from requests.exceptions import RequestException
3+
24
class VilfoException(Exception):
35
"""General Vilfo exception occurred."""
46

57
class AuthenticationException(VilfoException):
68
"""An exception occurred related to authentication."""
9+
10+
class NotFoundException(VilfoException):
11+
"""An exception indicating an API resource was not found."""
12+
13+
class VilfoRequestException(VilfoException, RequestException):
14+
"""An exception caught by Vilfo but raised by the requests library."""

0 commit comments

Comments
 (0)