mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-12-22 17:01:50 +00:00
Add exception handling in Router (when handling c2s messages)
This commit is contained in:
parent
f6d92ecba0
commit
400c5410e9
@ -40,6 +40,7 @@ namespace Zirconium.Core
|
||||
session.ConnectionHandler.SendMessage(serializedMsg);
|
||||
return;
|
||||
}
|
||||
var handlerTasks = new List<Task>();
|
||||
foreach (var h in handlers)
|
||||
{
|
||||
if (h.IsAuthorizationRequired())
|
||||
@ -59,15 +60,15 @@ namespace Zirconium.Core
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Warning(e.Message);
|
||||
var errorMsg = OtherUtils.GenerateProtocolError(
|
||||
message,
|
||||
"unauthorized",
|
||||
"Unauthorized access",
|
||||
new Dictionary<string, object>()
|
||||
);
|
||||
errorMsg.From = _app.Config.ServerID;
|
||||
var serializedMsg = JsonConvert.SerializeObject(errorMsg);
|
||||
|
||||
var serializedMsg = JsonConvert.SerializeObject(
|
||||
OtherUtils.GenerateProtocolError(
|
||||
message,
|
||||
"unauthorized",
|
||||
"Unauthorized access",
|
||||
new Dictionary<string, object>()
|
||||
)
|
||||
);
|
||||
session.ConnectionHandler.SendMessage(serializedMsg);
|
||||
return;
|
||||
}
|
||||
@ -77,11 +78,17 @@ namespace Zirconium.Core
|
||||
}
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
// probably need to wrap whole foreach body, not only HandleMessage call - need to investigate
|
||||
h.HandleMessage(session, message);
|
||||
});
|
||||
handlerTasks.Add(task);
|
||||
}
|
||||
try {
|
||||
Task.WaitAll(handlerTasks.ToArray());
|
||||
} catch (Exception e) {
|
||||
Log.Error(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user