eclipse / paho.mqtt.rust

paho.mqtt.rust
Other
516 stars 102 forks source link

how to catch tcp connect time out error? #173

Closed heliping closed 1 year ago

heliping commented 1 year ago

I use mqtt with backend to send mqtt message. when I input the wrong ip, I need the api reback error message, but now only pending. my code like this

 let cli = match mqtt::Client::new(options) {
        Err(e) => {
            info!("connect error : {:?}", e);   
            return Err(e.to_string())
        },
        Ok(c) => c,
    };

I need the tcp connect when timeout can return the error to client. but now nothing.

The error message by console.

thread 'actix-rt|system:0|arbiter:0' panicked at 'called `Result::unwrap()` on an `Err` value: "[-1] TCP connect timeout"', src/controllers/wkc.rs:19:10
fpagliughi commented 1 year ago

The connection error doesn't happen when you create the client with Client::new(), but rather when you call connect() on the client.

You appear to be getting the connection result in your code at src/controllers/wkc.rs:19 and attempting to .unwrap() the error, resulting in a panic.

heliping commented 1 year ago

cool, sloved, thanks.