diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c1ac99..8feecb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Edge +- include invalid status code when raising handshake error + ## 1.2.11 - remove unused base64 require that would cause issues in Ruby 3.4 diff --git a/lib/websocket/error.rb b/lib/websocket/error.rb index ec63e9f..bef5064 100644 --- a/lib/websocket/error.rb +++ b/lib/websocket/error.rb @@ -108,6 +108,12 @@ def message end class InvalidStatusCode < ::WebSocket::Error::Handshake + attr_reader :invalid_status_code + + def initialize(invalid_status_code) + @invalid_status_code = invalid_status_code + end + def message :invalid_status_code end diff --git a/lib/websocket/handshake/client.rb b/lib/websocket/handshake/client.rb index d1ae0e0..46a085a 100644 --- a/lib/websocket/handshake/client.rb +++ b/lib/websocket/handshake/client.rb @@ -123,7 +123,14 @@ def parse_first_line(line) line_parts = line.match(FIRST_LINE) raise WebSocket::Error::Handshake::InvalidHeader unless line_parts status = line_parts[1] - raise WebSocket::Error::Handshake::InvalidStatusCode unless status == '101' + + # The signature for the error doesn't take the message as the first + # argument, but rather the status code. So this should use the + # initializer to create the error. + # + # rubocop:disable Style/RaiseArgs + raise WebSocket::Error::Handshake::InvalidStatusCode.new(status) unless status == '101' + # rubocop:enable Style/RaiseArgs end end end