Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/comfy_sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
17 changes: 17 additions & 0 deletions tests/test_error_mapping.py
Original file line number Diff line number Diff line change
@@ -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
Loading