Compare commits

...

2 Commits

Author SHA1 Message Date
e0e0310f7f Merge pull request 'improve error handling' (#1) from fix/connection-issue into main
All checks were successful
Build and Publish / Build Yale Access Backend (push) Successful in 40s
Build and Publish / Build Yale Access Frontend (push) Successful in 55s
Build and Publish / Push Yale Access Backend Docker Image (push) Successful in 15s
Build and Publish / Push Yale Access Frontend Docker Image (push) Successful in 1m8s
Reviewed-on: #1
2025-04-12 09:50:07 +10:00
25bd37801f 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
2025-04-12 09:24:37 +10:00

View File

@ -56,23 +56,33 @@ namespace YaleAccess.Services
// Flag to indicate if the driver is ready to use // Flag to indicate if the driver is ready to use
bool isReady = false; 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 // Subscribe to the driver ready event
driver.DriverReady += () => driver.DriverReady += () =>
{ {
isReady = true; isReady = true;
}; };
driver.StartUpError += (message) => driver.StartUpError += (error) =>
{ {
throw new Exception(message); message = error;
}; };
// Wait for the driver to be ready // 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); 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 // Get the lock node from the driver
lockNode = driver.Controller.Nodes.Get(devicesOptions.YaleLockNodeId); lockNode = driver.Controller.Nodes.Get(devicesOptions.YaleLockNodeId);
} }