1tgr / rust-websocket-lite

A fast, low-overhead WebSocket client
MIT License
115 stars 17 forks source link

include reason in error message if upgrade fails #317

Closed fbenkstein closed 1 year ago

fbenkstein commented 1 year ago

When an Upgrade fails with a non-101 status code the server might include a reason message which can help in debugging. In my case I missed a query parameter which was difficult to find out without actually cloning this project locally and annotating the code with dbg!() calls. With this change we just add the reason to the error message if it's present - debug-printed so there should not be a danger of weird characters sneaking in. This is adding an explicit Result::expect call but as far as I can tell this can only happen if the Debug::fmt implementation of &str fails, hopefully never. Also, an implicit expect is already present in each call to format! which are used in various other places in the library.