Graceful fail-out for when geth is unavailable

This commit is contained in:
Ben 2025-06-10 14:40:14 +02:00
parent c5ff76db69
commit 36cc93ebee
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B

View File

@ -8,9 +8,13 @@ namespace BiblioTech
{
protected override async Task Invoke(CommandContext context)
{
var gethConnector = GethConnector.GethConnector.Initialize(Program.Log);
var gethConnector = GetGeth();
if (gethConnector == null)
{
await context.Followup("Blockchain operations are (temporarily) unavailable.");
return;
}
if (gethConnector == null) return;
var gethNode = gethConnector.GethNode;
var contracts = gethConnector.CodexContracts;
@ -23,6 +27,19 @@ namespace BiblioTech
await Execute(context, gethNode, contracts);
}
private GethConnector.GethConnector? GetGeth()
{
try
{
return GethConnector.GethConnector.Initialize(Program.Log);
}
catch (Exception ex)
{
Program.Log.Error("Failed to initialize geth connector: " + ex);
return null;
}
}
protected abstract Task Execute(CommandContext context, IGethNode gethNode, ICodexContracts contracts);
}
}