Skip to content

Commit

Permalink
Better error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 24, 2024
1 parent b6f8e19 commit e1ef8f9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ def close(error = nil)
end

def open!
if @state == :idle
@state = :open
else
unless @state == :idle
raise ProtocolError, "Cannot open connection in state: #{@state}!"
end

@state = :open

return self
end

Expand All @@ -231,7 +231,7 @@ def write_request(authority, method, path, version, headers)

def write_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
unless @state == :open or @state == :half_closed_remote
raise ProtocolError, "Cannot write response in #{@state}!"
raise ProtocolError, "Cannot write response in state: #{@state}!"
end

# Safari WebSockets break if no reason is given:
Expand All @@ -242,7 +242,7 @@ def write_response(version, status, headers, reason = Reason::DESCRIPTIONS[statu

def write_interim_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
unless @state == :open or @state == :half_closed_remote
raise ProtocolError, "Cannot write interim response in #{@state}!"
raise ProtocolError, "Cannot write interim response in state: #{@state}!"
end

@stream.write("#{version} #{status} #{reason}\r\n")
Expand Down Expand Up @@ -336,7 +336,7 @@ def read_response_line

def read_response(method)
unless @state == :open or @state == :half_closed_local
raise ProtocolError, "Cannot read response in #{@state}!"
raise ProtocolError, "Cannot read response in state: #{@state}!"
end

version, status, reason = read_response_line
Expand Down Expand Up @@ -381,7 +381,7 @@ def send_end_stream!
elsif @state == :half_closed_remote
self.close!
else
raise ProtocolError, "Cannot send end stream in #{@state}!"
raise ProtocolError, "Cannot send end stream in state: #{@state}!"
end
end

Expand Down Expand Up @@ -590,7 +590,7 @@ def receive_end_stream!
elsif @state == :half_closed_local
self.close!
else
raise ProtocolError, "Cannot receive end stream in #{@state}!"
raise ProtocolError, "Cannot receive end stream in state: #{@state}!"
end
end

Expand Down

0 comments on commit e1ef8f9

Please sign in to comment.