Skip to content

Commit

Permalink
fix: add exception with option
Browse files Browse the repository at this point in the history
  • Loading branch information
marksie1988 committed Apr 17, 2023
1 parent e030350 commit 73afc50
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pyarr/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ class PyarrMissingArgument(PyarrError):

class PyarrBadRequest(PyarrError):
"""Bad Request, possible bug."""


class PyarrServerError(PyarrError):
"""Server Error, missing or incorrect options."""

def __init__(self, message, response):
super().__init__(message)
self.response = response
11 changes: 9 additions & 2 deletions pyarr/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
PyarrConnectionError,
PyarrMethodNotAllowed,
PyarrResourceNotFound,
PyarrServerError,
PyarrUnauthorizedError,
)
from .types import _ReturnType
Expand Down Expand Up @@ -241,11 +242,17 @@ def _process_response(
)
if res.status_code == 404:
raise PyarrResourceNotFound("Resource not found")
if res.status_code == 502:
raise PyarrBadGateway("Bad Gateway. Check your server is accessible")
if res.status_code == 405:
raise PyarrMethodNotAllowed(f"The endpoint {res.url} is not allowed")
if res.status_code == 500:
raise PyarrServerError(
f"Internal Server Error: {res.json()['message']}",
res.json(),
)
if res.status_code == 502:
raise PyarrBadGateway("Bad Gateway. Check your server is accessible.")

print(res.status_code)
content_type = res.headers.get("Content-Type", "")
if "application/json" in content_type:
return res.json()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyarr"
version = "5.0.0"
version = "5.0.1"
description = "Synchronous Sonarr, Radarr, Lidarr and Readarr API's for Python"
authors = ["Steven Marks <marksie1988@users.noreply.github.com>"]
license = "MIT"
Expand Down

0 comments on commit 73afc50

Please sign in to comment.