Skip to content

Commit 10fbf4c

Browse files
committed
feat: address copilot comments
1 parent e6ed185 commit 10fbf4c

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

openfga_sdk/api_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,11 @@ async def __call_api(
321321
and TelemetryAttributes.fga_client_request_method
322322
in _telemetry_attributes
323323
):
324-
e.operation_name = _telemetry_attributes[
324+
operation_name = _telemetry_attributes.get(
325325
TelemetryAttributes.fga_client_request_method
326-
].lower()
326+
)
327+
if isinstance(operation_name, str):
328+
e.operation_name = operation_name.lower()
327329
raise e
328330
except ApiException as e:
329331
e.body = e.body.decode("utf-8")
@@ -361,9 +363,11 @@ async def __call_api(
361363
and TelemetryAttributes.fga_client_request_method
362364
in _telemetry_attributes
363365
):
364-
e.operation_name = _telemetry_attributes[
366+
operation_name = _telemetry_attributes.get(
365367
TelemetryAttributes.fga_client_request_method
366-
].lower()
368+
)
369+
if isinstance(operation_name, str):
370+
e.operation_name = operation_name.lower()
367371
raise
368372

369373
self.last_response = response_data

openfga_sdk/exceptions.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def __init__(self, msg, path_to_item=None):
116116

117117

118118
class ApiException(OpenApiException):
119-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
119+
def __init__(
120+
self, status=None, reason=None, http_resp=None, *, operation_name=None
121+
):
120122
if http_resp:
121123
try:
122124
headers = http_resp.headers.items()
@@ -297,38 +299,52 @@ def is_server_error(self):
297299

298300

299301
class NotFoundException(ApiException):
300-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
301-
super().__init__(status, reason, http_resp, operation_name)
302+
def __init__(
303+
self, status=None, reason=None, http_resp=None, *, operation_name=None
304+
):
305+
super().__init__(status, reason, http_resp, operation_name=operation_name)
302306

303307

304308
class UnauthorizedException(ApiException):
305-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
306-
super().__init__(status, reason, http_resp, operation_name)
309+
def __init__(
310+
self, status=None, reason=None, http_resp=None, *, operation_name=None
311+
):
312+
super().__init__(status, reason, http_resp, operation_name=operation_name)
307313

308314

309315
class ForbiddenException(ApiException):
310-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
311-
super().__init__(status, reason, http_resp, operation_name)
316+
def __init__(
317+
self, status=None, reason=None, http_resp=None, *, operation_name=None
318+
):
319+
super().__init__(status, reason, http_resp, operation_name=operation_name)
312320

313321

314322
class ServiceException(ApiException):
315-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
316-
super().__init__(status, reason, http_resp, operation_name)
323+
def __init__(
324+
self, status=None, reason=None, http_resp=None, *, operation_name=None
325+
):
326+
super().__init__(status, reason, http_resp, operation_name=operation_name)
317327

318328

319329
class ValidationException(ApiException):
320-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
321-
super().__init__(status, reason, http_resp, operation_name)
330+
def __init__(
331+
self, status=None, reason=None, http_resp=None, *, operation_name=None
332+
):
333+
super().__init__(status, reason, http_resp, operation_name=operation_name)
322334

323335

324336
class AuthenticationError(ApiException):
325-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
326-
super().__init__(status, reason, http_resp, operation_name)
337+
def __init__(
338+
self, status=None, reason=None, http_resp=None, *, operation_name=None
339+
):
340+
super().__init__(status, reason, http_resp, operation_name=operation_name)
327341

328342

329343
class RateLimitExceededError(ApiException):
330-
def __init__(self, status=None, reason=None, http_resp=None, operation_name=None):
331-
super().__init__(status, reason, http_resp, operation_name)
344+
def __init__(
345+
self, status=None, reason=None, http_resp=None, *, operation_name=None
346+
):
347+
super().__init__(status, reason, http_resp, operation_name=operation_name)
332348

333349

334350
def render_path(path_to_item):

openfga_sdk/sync/api_client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,12 @@ def __call_api(
320320
and TelemetryAttributes.fga_client_request_method
321321
in _telemetry_attributes
322322
):
323-
# Convert operation name to lowercase for consistency
324-
e.operation_name = _telemetry_attributes[
323+
operation_name = _telemetry_attributes.get(
325324
TelemetryAttributes.fga_client_request_method
326-
].lower()
327-
raise e
325+
)
326+
if isinstance(operation_name, str):
327+
e.operation_name = operation_name.lower()
328+
raise
328329
except ApiException as e:
329330
e.body = e.body.decode("utf-8")
330331
response_type = response_types_map.get(e.status, None)
@@ -362,9 +363,11 @@ def __call_api(
362363
and TelemetryAttributes.fga_client_request_method
363364
in _telemetry_attributes
364365
):
365-
e.operation_name = _telemetry_attributes[
366+
operation_name = _telemetry_attributes.get(
366367
TelemetryAttributes.fga_client_request_method
367-
].lower()
368+
)
369+
if isinstance(operation_name, str):
370+
e.operation_name = operation_name.lower()
368371
raise
369372

370373
self.last_response = response_data

test/error_integration_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ async def fga_client(self):
9292
try:
9393
await client.delete_store()
9494
except Exception:
95+
# Ignore exceptions during cleanup (e.g., store may already be deleted or server unavailable)
9596
pass # Ignore cleanup errors
9697

9798
async def test_write_validation_error_invalid_type(self, fga_client):

0 commit comments

Comments
 (0)