From d0fa09df4a151f53b0368a06f8232050dd041c34 Mon Sep 17 00:00:00 2001 From: wei-hai Date: Tue, 21 Jul 2026 18:08:56 -0700 Subject: [PATCH] fix: map entity-specific 404 codes (job/asset_not_found) to NotFound public-api returns entity-specific 404 error codes (job_not_found, asset_not_found) even though the spec documents the generic not_found, so `client.jobs.get()` raised a bare ApiError instead of the typed NotFound the SDK promises. Map both to NotFound. (Server/spec reconciliation of the code set is a separate follow-up.) Co-Authored-By: Claude Opus 4.8 --- src/comfy_sdk/exceptions.py | 6 ++++++ tests/test_error_mapping.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/test_error_mapping.py diff --git a/src/comfy_sdk/exceptions.py b/src/comfy_sdk/exceptions.py index 46ef565..412e5e0 100644 --- a/src/comfy_sdk/exceptions.py +++ b/src/comfy_sdk/exceptions.py @@ -108,6 +108,12 @@ def __init__(self, message: str, *, error: JobError | None = None) -> None: "idempotency_key_reuse": IdempotencyKeyReuse, "insufficient_credits": InsufficientCredits, "not_found": NotFound, + # public-api currently returns entity-specific 404 codes even though the + # spec documents the generic `not_found`; map them so a missing job/asset + # still raises the typed NotFound. (Server/spec reconciliation of the code + # set is a separate follow-up.) + "job_not_found": NotFound, + "asset_not_found": NotFound, "unauthorized": Unauthorized, "forbidden": Forbidden, } diff --git a/tests/test_error_mapping.py b/tests/test_error_mapping.py new file mode 100644 index 0000000..265f8ca --- /dev/null +++ b/tests/test_error_mapping.py @@ -0,0 +1,17 @@ +"""to_sdk_error must map the server's 404 codes to the typed NotFound.""" + +from __future__ import annotations + +import pytest + +from comfy_low.errors import ApiError +from comfy_sdk.exceptions import NotFound, to_sdk_error + + +@pytest.mark.parametrize("code", ["not_found", "job_not_found", "asset_not_found"]) +def test_404_codes_map_to_notfound(code: str) -> None: + # public-api returns entity-specific 404 codes (job_not_found / asset_not_found) + # alongside the spec's generic not_found; all must raise the typed NotFound. + err = to_sdk_error(ApiError("not found", code=code, http_status=404)) + assert isinstance(err, NotFound) + assert err.code == code