Skip to content

Commit

Permalink
Merge pull request #114 from Habbie/wsclose
Browse files Browse the repository at this point in the history
turn websocket close from a confusing error into a clear one
  • Loading branch information
Habbie authored Oct 4, 2024
2 parents eaad4b4 + 5b3aa54 commit bd05b20
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/WSConn.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include "WSConn.hpp"
#include "src/logger.hpp"
#include <iostream>

using std::cout;
Expand Down Expand Up @@ -66,6 +67,17 @@ std::string WSConn::recv(void)
// cout<<"RESULT:"<<endl;
// cout<<result<<endl;
// cout<<"END RESULT"<<endl;

if (meta->flags & CURLWS_CLOSE) {
uint16_t reason = 0;

if (result.size() >= 2) {
reason = ((unsigned char)result[0] << 8) + (unsigned char)result[1];
}
g_log << Logger::LogLevel::Error << "got CURL_WS_CLOSE, reason=" << reason << endl;
throw std::runtime_error("HA websocket disconnected");
}

return result;
}

Expand Down

0 comments on commit bd05b20

Please sign in to comment.