@@ -734,12 +734,16 @@ HTTP endpoint (usually :5001). Applications integrating on top of the
734
734
} catch (ConnectException e ) {
735
735
throw new RuntimeException ("Couldn't connect to IPFS daemon at " +target +"\n Is IPFS running?" );
736
736
} catch (IOException e ) {
737
- InputStream errorStream = conn .getErrorStream ();
738
- String err = errorStream == null ? e .getMessage () : new String (readFully (errorStream ));
739
- throw new RuntimeException ("IOException contacting IPFS daemon.\n " +err +"\n Trailer: " + conn .getHeaderFields ().get ("Trailer" ), e );
737
+ throw extractError (e , conn );
740
738
}
741
739
}
742
740
741
+ public static RuntimeException extractError (IOException e , HttpURLConnection conn ) {
742
+ InputStream errorStream = conn .getErrorStream ();
743
+ String err = errorStream == null ? e .getMessage () : new String (readFully (errorStream ));
744
+ return new RuntimeException ("IOException contacting IPFS daemon.\n " +err +"\n Trailer: " + conn .getHeaderFields ().get ("Trailer" ), e );
745
+ }
746
+
743
747
private void getObjectStream (InputStream in , Consumer <byte []> processor , Consumer <IOException > error ) {
744
748
byte LINE_FEED = (byte )10 ;
745
749
@@ -789,11 +793,7 @@ private static InputStream getStream(URL target, int connectTimeoutMillis, int r
789
793
try {
790
794
return conn .getInputStream ();
791
795
} catch (IOException e ) {
792
- e .printStackTrace ();
793
- InputStream errorStream = conn .getErrorStream ();
794
- String err = errorStream == null ? e .getMessage () : new String (readFully (errorStream ));
795
- List <String > trailer = conn .getHeaderFields ().get ("Trailer" );
796
- throw new RuntimeException ("IOException contacting IPFS daemon.\n " +err +"\n Trailer: " + trailer , e );
796
+ throw extractError (e , conn );
797
797
}
798
798
}
799
799
@@ -812,8 +812,12 @@ private static byte[] post(URL target, byte[] body, Map<String, String> headers,
812
812
out .flush ();
813
813
out .close ();
814
814
815
- InputStream in = conn .getInputStream ();
816
- return readFully (in );
815
+ try {
816
+ InputStream in = conn .getInputStream ();
817
+ return readFully (in );
818
+ } catch (IOException e ) {
819
+ throw extractError (e , conn );
820
+ }
817
821
}
818
822
819
823
private static final byte [] readFully (InputStream in ) {
0 commit comments