Skip to content

Commit

Permalink
add not authenticated error
Browse files Browse the repository at this point in the history
  • Loading branch information
engineerjoe440 committed Dec 30, 2023
1 parent 5f281d3 commit 513cc08
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pychee/pychee.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@

from requests import Session

__version__ = '0.2.3'
__version__ = '0.2.4'

class LycheeForbidden(Exception):
class LycheeError(Exception):
"""Raised for general Lychee errors."""

class LycheeNotAuthenticated(LycheeError):
"""Raised when a call results in an unauthenticated error."""

class LycheeForbidden(LycheeError):
"""Raised when the Lychee request is unauthorized."""

class LycheeNotFound(Exception):
class LycheeNotFound(LycheeError):
"""Raised when the requested resource was not found."""

class LycheeError(Exception):
"""Raised for general Lychee errors."""

#FIXME add error code handling
#FIXME adjust to API sending JSON because we changed Accept
#FIXME fix type hints...
Expand All @@ -39,6 +42,10 @@ class LycheeAPISession(Session):
'"Error: validation failed"'
]

NOT_AUTHENTICATED_MESSAGES = [
'User is not authenticated',
]

NOT_FOUND_MESSAGES = [
'"Error: no pictures found!"'
]
Expand Down Expand Up @@ -68,8 +75,10 @@ def request(self, method, url, *args, **kwargs):
# Update CSRF header if changed
if response.text in self.FORBID_MESSAGES:
raise LycheeForbidden(response.text)
if response.text in self.NOT_FOUND_MESSAGES:
elif response.text in self.NOT_FOUND_MESSAGES:
raise LycheeNotFound(response.text)
elif response.text in self.NOT_AUTHENTICATED_MESSAGES:
raise LycheeNotAuthenticated(response.text)
if response.text == 'false' or response.text is None:
raise LycheeError('Could be unauthorized, wrong args, who knows?')
return response
Expand Down

0 comments on commit 513cc08

Please sign in to comment.