diff --git a/Server.cs b/Server.cs index d5e0d6c..15a29c0 100644 --- a/Server.cs +++ b/Server.cs @@ -78,20 +78,22 @@ namespace HermesSocketLibrary await socket.Send(5, new LoggingMessage("Received no data in the message.", HermesLoggingLevel.Warn)); continue; } - else if (obj.OpCode == 0) - obj.Data = JsonSerializer.Deserialize(obj.Data.ToString(), _options); + + string data = obj.Data.ToString()!; + if (obj.OpCode == 0) + obj.Data = JsonSerializer.Deserialize(data, _options); else if (obj.OpCode == 1) - obj.Data = JsonSerializer.Deserialize(obj.Data.ToString(), _options); + obj.Data = JsonSerializer.Deserialize(data, _options); else if (obj.OpCode == 3) - obj.Data = JsonSerializer.Deserialize(obj.Data.ToString(), _options); + obj.Data = JsonSerializer.Deserialize(data, _options); else if (obj.OpCode == 5) - obj.Data = JsonSerializer.Deserialize(obj.Data.ToString(), _options); + obj.Data = JsonSerializer.Deserialize(data, _options); else if (obj.OpCode == 6) - obj.Data = JsonSerializer.Deserialize(obj.Data.ToString(), _options); + obj.Data = JsonSerializer.Deserialize(data, _options); else if (obj.OpCode == 7) - obj.Data = JsonSerializer.Deserialize(obj.Data.ToString(), _options); + obj.Data = JsonSerializer.Deserialize(data, _options); else if (obj.OpCode == 8) - obj.Data = JsonSerializer.Deserialize(obj.Data.ToString(), _options); + obj.Data = JsonSerializer.Deserialize(data, _options); else { await socket.Send(5, new LoggingMessage("Received an invalid message: " + message, HermesLoggingLevel.Error)); diff --git a/Socket/Handlers/RequestHandler.cs b/Socket/Handlers/RequestHandler.cs index 6a816fd..6c57742 100644 --- a/Socket/Handlers/RequestHandler.cs +++ b/Socket/Handlers/RequestHandler.cs @@ -35,17 +35,18 @@ namespace HermesSocketServer.Socket.Handlers _logger.Error(e, $"Failed to grant a request of type '{data.Type}'."); } - if (result == null || !result.Success) + if (result == null) return; var ack = new RequestAckMessage() { Request = data, - Data = result.Result, - Nounce = data.Nounce + Data = result.Success ? result.Result : null, + Nounce = data.Nounce, + Error = result.Success ? null : result.Result?.ToString() }; - if (!result.NotifyClientsOnAccount) + if (!result.NotifyClientsOnAccount || !result.Success) { await sender.Send(4, ack); return;