Handle ConnectionAbortedException in controllers
Add specific handling for ConnectionAbortedException in ChatController, GamesController, and ChallengesController to explicitly manage cases where the client closes the connection, ensuring graceful exception handling and improved code clarity.
This commit is contained in:
@@ -7,6 +7,7 @@ using Aiursoft.ChessServer.Models;
|
||||
using Aiursoft.ChessServer.Models.ViewModels;
|
||||
using Aiursoft.CSTools.Services;
|
||||
using Aiursoft.WebTools.Attributes;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Aiursoft.ChessServer.Controllers;
|
||||
@@ -157,6 +158,10 @@ public class ChallengesController (
|
||||
{
|
||||
// Ignore. This happens when the client closes the connection.
|
||||
}
|
||||
catch (ConnectionAbortedException)
|
||||
{
|
||||
// Ignore. This happens when the client closes the connection.
|
||||
}
|
||||
finally
|
||||
{
|
||||
outSub.Unsubscribe();
|
||||
|
||||
@@ -6,6 +6,7 @@ using Aiursoft.ChessServer.Attributes;
|
||||
using Aiursoft.ChessServer.Data;
|
||||
using Aiursoft.ChessServer.Models;
|
||||
using Aiursoft.WebTools.Attributes;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Aiursoft.ChessServer.Controllers;
|
||||
@@ -50,6 +51,10 @@ public class ChatController(InMemoryDatabase database) : ControllerBase
|
||||
{
|
||||
// Ignore. This happens when the client closes the connection.
|
||||
}
|
||||
catch (ConnectionAbortedException)
|
||||
{
|
||||
// Ignore. This happens when the client closes the connection.
|
||||
}
|
||||
finally
|
||||
{
|
||||
outSub.Unsubscribe();
|
||||
|
||||
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Aiursoft.AiurObserver.Extensions;
|
||||
using Aiursoft.ChessServer.Attributes;
|
||||
using Aiursoft.WebTools.Attributes;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Aiursoft.ChessServer.Controllers;
|
||||
|
||||
@@ -88,6 +89,10 @@ public class GamesController(InMemoryDatabase database) : Controller
|
||||
{
|
||||
// Ignore. This happens when the client closes the connection.
|
||||
}
|
||||
catch (ConnectionAbortedException)
|
||||
{
|
||||
// Ignore. This happens when the client closes the connection.
|
||||
}
|
||||
finally
|
||||
{
|
||||
outSub.Unsubscribe();
|
||||
|
||||
Reference in New Issue
Block a user