Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions fishjam/api/_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import warnings
from typing import cast

from fishjam._openapi_client.client import AuthenticatedClient
Expand All @@ -16,12 +18,39 @@ def __init__(self, fishjam_id: str, management_token: str):
token=management_token,
headers={"x-fishjam-api-client": f"python-server/{get_version()}"},
)
self.warnings_shown = False

def _request(self, method, **kwargs):
response = method.sync_detailed(client=self.client, **kwargs)
self._handle_deprecation_header(response.headers)

if isinstance(response.parsed, Error):
response = cast(Response[Error], response)
raise HTTPError.from_response(response)

return response.parsed

def _handle_deprecation_header(self, headers):
deprecation_warning = headers.get("x-fishjam-api-deprecated")
if deprecation_warning and not self.warnings_shown:
self.warnings_shown = True
try:
deprecation_data = json.loads(deprecation_warning)
except (json.JSONDecodeError, TypeError, ValueError):
return

status = deprecation_data["status"]
msg = deprecation_data["message"]

if not status or not msg:
return

match status:
case "unsupported":
warnings.warn(message=msg, category=UserWarning, stacklevel=4)
case "deprecated":
warnings.warn(
message=msg, category=DeprecationWarning, stacklevel=4
)
case _:
pass