mirror of
https://github.com/livekit/livekit.git
synced 2026-05-25 20:45:13 +00:00
Return 404 with DeleteRoom/RemoveParticipant when deleting non-existent resources (#1860)
Fixes #1587
This commit is contained in:
@@ -127,6 +127,11 @@ func (s *RoomService) DeleteRoom(ctx context.Context, req *livekit.DeleteRoomReq
|
||||
if err := EnsureCreatePermission(ctx); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
if _, _, err := s.roomStore.LoadRoom(ctx, livekit.RoomName(req.Room), false); err == ErrRoomNotFound {
|
||||
return nil, twirp.NotFoundError("room not found")
|
||||
}
|
||||
|
||||
err := s.router.WriteRoomRTC(ctx, livekit.RoomName(req.Room), &livekit.RTCNodeMessage{
|
||||
Message: &livekit.RTCNodeMessage_DeleteRoom{
|
||||
DeleteRoom: req,
|
||||
@@ -187,6 +192,11 @@ func (s *RoomService) GetParticipant(ctx context.Context, req *livekit.RoomParti
|
||||
|
||||
func (s *RoomService) RemoveParticipant(ctx context.Context, req *livekit.RoomParticipantIdentity) (*livekit.RemoveParticipantResponse, error) {
|
||||
AppendLogFields(ctx, "room", req.Room, "participant", req.Identity)
|
||||
|
||||
if _, err := s.roomStore.LoadParticipant(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity)); err == ErrParticipantNotFound {
|
||||
return nil, twirp.NotFoundError("participant not found")
|
||||
}
|
||||
|
||||
err := s.writeParticipantMessage(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity), &livekit.RTCNodeMessage{
|
||||
Message: &livekit.RTCNodeMessage_RemoveParticipant{
|
||||
RemoveParticipant: req,
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func TestDeleteRoom(t *testing.T) {
|
||||
t.Run("normal deletion", func(t *testing.T) {
|
||||
t.Run("delete non-existent", func(t *testing.T) {
|
||||
svc := newTestRoomService(config.RoomConfig{})
|
||||
grant := &auth.ClaimGrants{
|
||||
Video: &auth.VideoGrant{
|
||||
@@ -29,7 +29,12 @@ func TestDeleteRoom(t *testing.T) {
|
||||
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
|
||||
Room: "testroom",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Error(t, err)
|
||||
if terr, ok := err.(twirp.Error); ok {
|
||||
require.Equal(t, twirp.NotFound, terr.Code())
|
||||
} else {
|
||||
require.Fail(t, "should be twirp error")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("missing permissions", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user