Send error messages to clients

This commit is contained in:
gion 2020-04-22 22:05:53 +02:00
parent 083d3272d0
commit 73fcbe90c0
2 changed files with 75 additions and 27 deletions

View File

@ -165,8 +165,14 @@ namespace Emby.Server.Implementations.Syncplay
if (user.Policy.SyncplayAccess != SyncplayAccess.CreateAndJoinGroups)
{
// TODO: report the error to the client
throw new ArgumentException("User does not have permission to create groups");
_logger.LogWarning("Syncplaymanager NewGroup: {0} does not have permission to create groups.", session.Id);
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.CreateGroupDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
}
if (IsSessionInGroup(session))
@ -187,8 +193,14 @@ namespace Emby.Server.Implementations.Syncplay
if (user.Policy.SyncplayAccess == SyncplayAccess.None)
{
// TODO: report the error to the client
throw new ArgumentException("User does not have access to syncplay");
_logger.LogWarning("Syncplaymanager JoinGroup: {0} does not have access to Syncplay.", session.Id);
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.JoinGroupDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
}
ISyncplayController group;
@ -196,17 +208,27 @@ namespace Emby.Server.Implementations.Syncplay
if (group == null)
{
_logger.LogWarning("Syncplaymanager JoinGroup: {0} does not exist.", groupId);
_logger.LogWarning("Syncplaymanager JoinGroup: {0} tried to join group {0} that does not exist.", session.Id, groupId);
var update = new GroupUpdate<string>();
update.Type = GroupUpdateType.NotInGroup;
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None);
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.GroupNotJoined
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
}
if (!HasAccessToItem(user, group.GetPlayingItemId()))
{
throw new ArgumentException("User does not have access to playing item");
_logger.LogWarning("Syncplaymanager JoinGroup: {0} does not have access to {1}.", session.Id, group.GetPlayingItemId());
var error = new GroupUpdate<string>()
{
GroupId = group.GetGroupId().ToString(),
Type = GroupUpdateType.LibraryAccessDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
}
if (IsSessionInGroup(session))
@ -230,9 +252,11 @@ namespace Emby.Server.Implementations.Syncplay
{
_logger.LogWarning("Syncplaymanager LeaveGroup: {0} does not belong to any group.", session.Id);
var update = new GroupUpdate<string>();
update.Type = GroupUpdateType.NotInGroup;
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None);
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.NotInGroup
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
}
group.SessionLeave(session);
@ -280,8 +304,14 @@ namespace Emby.Server.Implementations.Syncplay
if (user.Policy.SyncplayAccess == SyncplayAccess.None)
{
// TODO: same as LeaveGroup
throw new ArgumentException("User does not have access to syncplay");
_logger.LogWarning("Syncplaymanager HandleRequest: {0} does not have access to Syncplay.", session.Id);
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.JoinGroupDenied
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
}
ISyncplayController group;
@ -289,11 +319,13 @@ namespace Emby.Server.Implementations.Syncplay
if (group == null)
{
_logger.LogWarning("Syncplaymanager HandleRequest: {0} not in a group.", session.Id);
_logger.LogWarning("Syncplaymanager HandleRequest: {0} does not belong to any group.", session.Id);
var update = new GroupUpdate<string>();
update.Type = GroupUpdateType.NotInGroup;
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), update, CancellationToken.None);
var error = new GroupUpdate<string>()
{
Type = GroupUpdateType.NotInGroup
};
_sessionManager.SendSyncplayGroupUpdate(session.Id.ToString(), error, CancellationToken.None);
return;
}
group.HandleRequest(session, request);

View File

@ -1,37 +1,53 @@
namespace MediaBrowser.Model.Syncplay
{
/// <summary>
/// Enum GroupUpdateType
/// Enum GroupUpdateType.
/// </summary>
public enum GroupUpdateType
{
/// <summary>
/// The user-joined update. Tells members of a group about a new user.
/// </summary>
UserJoined = 0,
UserJoined,
/// <summary>
/// The user-left update. Tells members of a group that a user left.
/// </summary>
UserLeft = 1,
UserLeft,
/// <summary>
/// The group-joined update. Tells a user that the group has been joined.
/// </summary>
GroupJoined = 2,
GroupJoined,
/// <summary>
/// The group-left update. Tells a user that the group has been left.
/// </summary>
GroupLeft = 3,
GroupLeft,
/// <summary>
/// The group-wait update. Tells members of the group that a user is buffering.
/// </summary>
GroupWait = 4,
GroupWait,
/// <summary>
/// The prepare-session update. Tells a user to load some content.
/// </summary>
PrepareSession = 5,
PrepareSession,
/// <summary>
/// The not-in-group update. Tells a user that no group has been joined.
/// The not-in-group error. Tells a user that it doesn't belong to a group.
/// </summary>
NotInGroup = 7
NotInGroup,
/// <summary>
/// The group-not-joined error. Sent when a request to join a group fails.
/// </summary>
GroupNotJoined,
/// <summary>
/// The create-group-denied error. Sent when a user tries to create a group without required permissions.
/// </summary>
CreateGroupDenied,
/// <summary>
/// The join-group-denied error. Sent when a user tries to join a group without required permissions.
/// </summary>
JoinGroupDenied,
/// <summary>
/// The library-access-denied error. Sent when a user tries to join a group without required access to the library.
/// </summary>
LibraryAccessDenied
}
}