Please return non-generic errors from dial
marcopeereboom opened this issue · 1 comments
It would be helpful to return non-generic errors from https://github.com/nhooyr/websocket/blob/master/dial.go#L225-L251
For example, I use this package to run long lived connections thus it reconnects etc. The issue is that I can't determine if I hit a terminal condition vs a dial error. The error I am trying to handle is when connecting to the correct example path would be ws://localhost:1234/ws
and the connection isn't established that is a condition that can be retried. If by accident the config was set to "ws://localhost:1234/IAMWRONG" then the error is something alone the lines of an http 404 error; this would be a terminal condition and I could exit my app"
Thanks!
You can check that the HTTP response is non nil. If it is, that means the handshake failed for some reason and that is indeed likely terminal.
Any other error is returned as is from the net library and so you can refer to the net docs for how to check whether something is retryable or not. I believe there's an error interface.