mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-22 10:22:23 +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);
|
session.ConnectionHandler.SendMessage(serializedMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var handlerTasks = new List<Task>();
|
||||||
foreach (var h in handlers)
|
foreach (var h in handlers)
|
||||||
{
|
{
|
||||||
if (h.IsAuthorizationRequired())
|
if (h.IsAuthorizationRequired())
|
||||||
@ -59,15 +60,15 @@ namespace Zirconium.Core
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Warning(e.Message);
|
Log.Warning(e.Message);
|
||||||
|
var errorMsg = OtherUtils.GenerateProtocolError(
|
||||||
var serializedMsg = JsonConvert.SerializeObject(
|
|
||||||
OtherUtils.GenerateProtocolError(
|
|
||||||
message,
|
message,
|
||||||
"unauthorized",
|
"unauthorized",
|
||||||
"Unauthorized access",
|
"Unauthorized access",
|
||||||
new Dictionary<string, object>()
|
new Dictionary<string, object>()
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
errorMsg.From = _app.Config.ServerID;
|
||||||
|
var serializedMsg = JsonConvert.SerializeObject(errorMsg);
|
||||||
|
|
||||||
session.ConnectionHandler.SendMessage(serializedMsg);
|
session.ConnectionHandler.SendMessage(serializedMsg);
|
||||||
return;
|
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
|
// probably need to wrap whole foreach body, not only HandleMessage call - need to investigate
|
||||||
h.HandleMessage(session, message);
|
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