♻️(backend) compare LiveKit errors to the SDK not-found code

Use TwirpErrorCode.NOT_FOUND rather than the bare string,
as the SIP service already does.
This commit is contained in:
davd-gzl
2026-10-20 00:10:13 +08:00
committed by briquet
parent da3ebc3564
commit d3302c8644
2 changed files with 8 additions and 6 deletions
@@ -13,6 +13,7 @@ from livekit.api import (
MuteRoomTrackRequest,
RoomParticipantIdentity,
TwirpError,
TwirpErrorCode,
UpdateParticipantRequest,
)
from livekit.protocol.models import ParticipantInfo
@@ -53,7 +54,7 @@ class ParticipantsManagement:
)
except (TwirpError, TimeoutError) as e:
if isinstance(e, TwirpError) and e.code == "not_found":
if isinstance(e, TwirpError) and e.code == TwirpErrorCode.NOT_FOUND:
logger.warning(
"Participant %s not found in room %s, skipping muting",
identity,
@@ -96,7 +97,7 @@ class ParticipantsManagement:
RoomParticipantIdentity(room=room_name, identity=identity)
)
except (TwirpError, TimeoutError) as e:
if isinstance(e, TwirpError) and e.code == "not_found":
if isinstance(e, TwirpError) and e.code == TwirpErrorCode.NOT_FOUND:
logger.warning(
"Participant %s not found in room %s, skipping removing",
identity,
@@ -141,7 +142,7 @@ class ParticipantsManagement:
)
except (TwirpError, TimeoutError) as e:
if isinstance(e, TwirpError) and e.code == "not_found":
if isinstance(e, TwirpError) and e.code == TwirpErrorCode.NOT_FOUND:
logger.warning(
"Participant %s not found in room %s, skipping update",
identity,
@@ -204,7 +205,7 @@ class ParticipantsManagement:
)
)
except (TwirpError, TimeoutError) as e:
if isinstance(e, TwirpError) and e.code == "not_found":
if isinstance(e, TwirpError) and e.code == TwirpErrorCode.NOT_FOUND:
raise ParticipantNotFoundException("Participant does not exist") from e
logger.exception(
+3 -2
View File
@@ -14,6 +14,7 @@ from livekit.api import (
DeleteRoomRequest,
ListRoomsRequest,
TwirpError,
TwirpErrorCode,
UpdateRoomMetadataRequest,
)
@@ -81,7 +82,7 @@ class RoomManagement:
)
except (TwirpError, TimeoutError) as e:
if isinstance(e, TwirpError) and e.code == "not_found":
if isinstance(e, TwirpError) and e.code == TwirpErrorCode.NOT_FOUND:
raise RoomNotFoundException("Room does not exist") from e
logger.exception(
@@ -109,7 +110,7 @@ class RoomManagement:
await lkapi.room.delete_room(DeleteRoomRequest(room=room_name))
logger.info("Deleted LiveKit room %s", room_name)
except (TwirpError, TimeoutError) as e:
if isinstance(e, TwirpError) and e.code == "not_found":
if isinstance(e, TwirpError) and e.code == TwirpErrorCode.NOT_FOUND:
logger.warning(
"Room %s not found in LiveKit, skipping deletion",
room_name,