improve error handling #1
| @@ -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); | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user