Enhance error handling and logging in BotController, LiveTradingBotGrain, and BotService

- Added specific handling for ServiceUnavailableException in BotController to return user-friendly messages.
- Improved logging for Orleans exceptions in both BotController and BotService to provide clearer context during errors.
- Implemented verification of position closure status in LiveTradingBotGrain, including timeout handling for closing positions.
- Enhanced logging for critical and non-critical operations during bot stop processes to ensure better traceability.
This commit is contained in:
2025-11-23 21:48:21 +07:00
parent 411fc41bef
commit d10ce5e3ba
3 changed files with 182 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ using Managing.Application.ManageBot.Commands;
using Managing.Application.Shared;
using Managing.Common;
using Managing.Core;
using Managing.Core.Exceptions;
using Managing.Domain.Accounts;
using Managing.Domain.Backtests;
using Managing.Domain.Bots;
@@ -245,9 +246,26 @@ public class BotController : BaseController
return Ok(result);
}
catch (ServiceUnavailableException ex)
{
// ServiceUnavailableException is already user-friendly (e.g., from Orleans exception conversion)
_logger.LogWarning(ex, "Service unavailable error stopping bot {Identifier}", identifier);
return StatusCode(503, ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error stopping bot");
_logger.LogError(ex, "Error stopping bot {Identifier}", identifier);
// Check if this is an Orleans exception that wasn't caught earlier
if (OrleansExceptionHelper.IsOrleansException(ex))
{
var userMessage = OrleansExceptionHelper.GetUserFriendlyMessage(ex, "bot stop");
_logger.LogWarning(
"Orleans exception detected in controller for bot {Identifier}: {ExceptionType}",
identifier, ex.GetType().Name);
return StatusCode(503, userMessage);
}
return StatusCode(500, $"Error stopping bot: {ex.Message}");
}
}