File tree 3 files changed +11
-3
lines changed 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -105,10 +105,11 @@ def readpartial(size = BUFFER_SIZE)
105
105
106
106
# Reads data from socket up until headers are loaded
107
107
# @return [void]
108
+ # @raise [ResponseHeaderError] when unable to read response headers
108
109
def read_headers!
109
110
until @parser . headers?
110
111
result = read_more ( BUFFER_SIZE )
111
- raise ConnectionError , "couldn't read response headers" if result == :eof
112
+ raise ResponseHeaderError , "couldn't read response headers" if result == :eof
112
113
end
113
114
114
115
set_keep_alive
@@ -217,6 +218,7 @@ def set_keep_alive
217
218
218
219
# Feeds some more data into parser
219
220
# @return [void]
221
+ # @raise [SocketReadError] when unable to read from socket
220
222
def read_more ( size )
221
223
return if @parser . finished?
222
224
@@ -228,7 +230,7 @@ def read_more(size)
228
230
@parser << value
229
231
end
230
232
rescue IOError , SocketError , SystemCallError => e
231
- raise ConnectionError , "error reading from socket: #{ e } " , e . backtrace
233
+ raise SocketReadError , "error reading from socket: #{ e } " , e . backtrace
232
234
end
233
235
end
234
236
end
Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ class Error < StandardError; end
7
7
# Generic Connection error
8
8
class ConnectionError < Error ; end
9
9
10
+ # Types of Connection errors
11
+ class ResponseHeaderError < ConnectionError ; end
12
+ class SocketReadError < ConnectionError ; end
13
+ class SocketWriteError < ConnectionError ; end
14
+
10
15
# Generic Request error
11
16
class RequestError < Error ; end
12
17
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ def chunked?
108
108
109
109
private
110
110
111
+ # @raise [SocketWriteError] when unable to write to socket
111
112
def write ( data )
112
113
until data . empty?
113
114
length = @socket . write ( data )
@@ -118,7 +119,7 @@ def write(data)
118
119
rescue Errno ::EPIPE
119
120
raise
120
121
rescue IOError , SocketError , SystemCallError => e
121
- raise ConnectionError , "error writing to socket: #{ e } " , e . backtrace
122
+ raise SocketWriteError , "error writing to socket: #{ e } " , e . backtrace
122
123
end
123
124
end
124
125
end
You can’t perform that action at this time.
0 commit comments