Skip to content

Commit c1478cd

Browse files
committed
show deprecation warnings
1 parent fb05c3c commit c1478cd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

fishjam/api/_client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
import warnings
13
from typing import cast
24

35
from fishjam._openapi_client.client import AuthenticatedClient
@@ -16,12 +18,33 @@ def __init__(self, fishjam_id: str, management_token: str):
1618
token=management_token,
1719
headers={"x-fishjam-api-client": f"python-server/{get_version()}"},
1820
)
21+
self.warnings_shown = False
1922

2023
def _request(self, method, **kwargs):
2124
response = method.sync_detailed(client=self.client, **kwargs)
25+
self._handle_deprecation_header(response.headers)
2226

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

2731
return response.parsed
32+
33+
def _handle_deprecation_header(self, headers):
34+
deprecation_warning = headers.get("x-fishjam-api-deprecated")
35+
if deprecation_warning and not self.warnings_shown:
36+
self.warnings_shown = True
37+
deprecation_warning = json.loads(deprecation_warning)
38+
39+
status = deprecation_warning["status"]
40+
msg = deprecation_warning["message"]
41+
42+
match status:
43+
case "unsupported":
44+
warnings.warn(message=msg, category=UserWarning, stacklevel=4)
45+
case "deprecated":
46+
warnings.warn(
47+
message=msg, category=DeprecationWarning, stacklevel=4
48+
)
49+
case _:
50+
pass

0 commit comments

Comments
 (0)