@@ -67,9 +67,6 @@ public final class HttpOpener extends DefaultObjectPipe<String, ObjectReceiver<R
6767 private static final Pattern HEADER_FIELD_SEPARATOR_PATTERN = Pattern .compile (HEADER_FIELD_SEPARATOR );
6868 private static final Pattern HEADER_VALUE_SEPARATOR_PATTERN = Pattern .compile (HEADER_VALUE_SEPARATOR );
6969
70- private static final int SUCCESS_CODE_MIN = 200 ;
71- private static final int SUCCESS_CODE_MAX = 399 ;
72-
7370 private final Map <String , String > headers = new HashMap <>();
7471
7572 private Method method ;
@@ -260,11 +257,9 @@ public void process(final String input) {
260257 connection .getOutputStream ().write (requestBody .getBytes ());
261258 }
262259
263- final InputStream errorStream = connection .getErrorStream ();
264- final InputStream inputStream = errorStream != null ?
265- getErrorStream (errorStream ) : getInputStream (connection );
266-
260+ final InputStream inputStream = getInputStream (connection );
267261 final String contentEncoding = getEncoding (connection .getContentEncoding ());
262+
268263 getReceiver ().process (new InputStreamReader (inputStream , contentEncoding ));
269264 }
270265 catch (final IOException e ) {
@@ -294,30 +289,19 @@ private InputStream getInputStream(final HttpURLConnection connection) throws IO
294289 return connection .getInputStream ();
295290 }
296291 catch (final IOException e ) {
297- final int responseCode = connection .getResponseCode ();
298- if (responseCode >= SUCCESS_CODE_MIN && responseCode <= SUCCESS_CODE_MAX ) {
299- throw e ;
292+ final InputStream errorStream = connection .getErrorStream ();
293+ if (errorStream != null ) {
294+ return getErrorStream ( errorStream ) ;
300295 }
301296 else {
302- final StringBuilder sb = new StringBuilder (String .valueOf (responseCode ));
303-
304- final String responseMessage = connection .getResponseMessage ();
305- if (responseMessage != null ) {
306- sb .append (" - " ).append (responseMessage );
307- }
308-
309- return getErrorStream (getInputStream (sb .toString ()));
297+ throw e ;
310298 }
311299 }
312300 }
313301
314- private InputStream getInputStream (final String string ) {
315- return new ByteArrayInputStream (string .getBytes ());
316- }
317-
318302 private InputStream getErrorStream (final InputStream errorStream ) {
319303 if (errorPrefix != null ) {
320- final InputStream errorPrefixStream = getInputStream (errorPrefix );
304+ final InputStream errorPrefixStream = new ByteArrayInputStream (errorPrefix . getBytes () );
321305 return new SequenceInputStream (errorPrefixStream , errorStream );
322306 }
323307 else {
0 commit comments