improve error handling
All checks were successful
Build and Publish / Build Yale Access Backend (push) Successful in 35s
Build and Publish / Push Yale Access Backend Docker Image (push) Has been skipped
Build and Publish / Build Yale Access Backend (pull_request) Successful in 47s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Has been skipped
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 1m3s
Build and Publish / Build Yale Access Frontend (push) Successful in 1m49s
Build and Publish / Push Yale Access Frontend Docker Image (push) Has been skipped
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Has been skipped

This commit is contained in:
Liam Pietralla 2025-04-12 09:24:37 +10:00
parent f577617b4d
commit 25bd37801f

View File

@ -56,23 +56,33 @@ namespace YaleAccess.Services
// Flag to indicate if the driver is ready to use
bool isReady = false;
// Message and flag to indicate if there was an error starting the driver
string? message = null;
// Subscribe to the driver ready event
driver.DriverReady += () =>
{
isReady = true;
};
driver.StartUpError += (message) =>
driver.StartUpError += (error) =>
{
throw new Exception(message);
message = error;
};
// Wait for the driver to be ready
while (!isReady)
while (!isReady && message == null)
{
// Sleep for a short time to avoid busy waiting
Thread.Sleep(100);
}
// If there was an error starting the driver, throw an exception
if (message != null)
{
throw new Exception($"Failed to start the driver. Error message: {message}");
}
// Get the lock node from the driver
lockNode = driver.Controller.Nodes.Get(devicesOptions.YaleLockNodeId);
}