How to access errors thrown by AstalBluetooth.Device.connect_device
Have you read through the documentation?
- [x] Astal docs
- [x] Library references
- [x] FAQ
Describe your question I am using the Typescript SDK with GTK4 and am trying to write my Bluetooth module. AstalBluetooth.Device.connect_device states that there are possible errors: "NotReady, Failed, InProgress, AlreadyConnected".
How do I access those errors from typescript? I want to show an error message when the connection failed.
Describe what have you tried so far
I tried printing the properties and looking for attributes on them. Source just seems to return the device and I couldn't find anything in result (BTW, is there a way to use the VSCode debugger? Couldn't get it to work using AGS).
device.connect_device((source, result) => {
print(source);
print(result);
});
I also tried wrapping it in a try-catch but this never throws.
try {
device.connect_device((source, result) => {
print(source);
print(result);
});
} catch (error) {
print(error);
}
Thank you for the help and sorry if this is a simple question :)
Connect device is an async method. You have to use device.connect_device_finish(res) to access the return value and catch any errors.
e.g.
device.connect_device((_, res) => {
try {
device.connect_device_finish(res);
} catch (e) {
console.error(e);
}
});