@@ -1173,8 +1173,8 @@ private BufferedInputStream downloadFileData(String jobId, URL restEndpoint) thr
11731173 return new BufferedInputStream (stream );
11741174 }
11751175
1176- private HttpURLConnection setConnection (String jobId , URL restEndpoint ) throws IOException {
1177- HttpURLConnection connection = openConnection ("GET" , restEndpoint );
1176+ private HttpURLConnection setConnection (String jobId , URL restEndpoint , String method ) throws IOException {
1177+ HttpURLConnection connection = openConnection (method , restEndpoint );
11781178
11791179 int responseCode = connection .getResponseCode ();
11801180 logger .log (Level .FINEST , "{0} - {1} for: {2}" , new Object [] { responseCode , restEndpoint , jobId });
@@ -1189,6 +1189,9 @@ private HttpURLConnection setConnection(String jobId, URL restEndpoint) throws I
11891189 errorDetails = ErrorExplainers .HARMissing ();
11901190 } else if (path .endsWith ("log" ) || path .endsWith ("json" )) {
11911191 errorDetails = ErrorExplainers .LogNotFound ();
1192+ } else if (path .contains ("tunnels" )) {
1193+ errorDetails = ErrorExplainers .TunnelNotFound ();
1194+ throw new SauceException .NotFound (String .join (System .lineSeparator (), errorDetails ));
11921195 }
11931196
11941197 String error = ErrorExplainers .resourceMissing ();
@@ -1228,6 +1231,14 @@ private HttpURLConnection setConnection(String jobId, URL restEndpoint) throws I
12281231 return connection ;
12291232 }
12301233
1234+ private HttpURLConnection setConnection (String jobId , URL restEndpoint ) throws IOException {
1235+ return setConnection (jobId , restEndpoint , "GET" );
1236+ }
1237+
1238+ private HttpURLConnection setConnection (URL restEndpoint , String method ) throws IOException {
1239+ return setConnection ("" , restEndpoint , method );
1240+ }
1241+
12311242 private boolean saveAsset (String jobId , String assetName , String location , String fileName ) {
12321243 return handleErrorAtDownloadGracefully (() -> saveAssetOrThrowException (jobId , assetName , location , fileName ));
12331244 }
@@ -1613,19 +1624,26 @@ protected String encodeAuthentication() {
16131624 * Invokes the Sauce REST API to delete a tunnel.
16141625 *
16151626 * @param tunnelId Identifier of the tunnel to delete
1627+ * @return BufferedInputStream with response from server
16161628 */
1617- public void deleteTunnel (String tunnelId ) {
1618-
1629+ public BufferedInputStream deleteTunnel (String tunnelId ) throws IOException {
16191630 HttpURLConnection connection = null ;
16201631 try {
16211632 URL restEndpoint = buildURL (username + "/tunnels/" + tunnelId );
1622- connection = openConnection ("DELETE" , restEndpoint );
1623- connection .getOutputStream ().write ("" .getBytes ());
1633+ connection = setConnection (restEndpoint , "DELETE" );
16241634 } catch (IOException e ) {
1625- logger .log (Level .WARNING , "Error stopping Sauce Job" , e );
1635+ Throwable throwable = e .getCause ();
1636+
1637+ if (throwable instanceof SauceException .NotAuthorized ) {
1638+ throw (SauceException .NotAuthorized ) throwable ;
1639+ } else if (throwable instanceof SauceException .NotFound ) {
1640+ throw (SauceException .NotFound ) throwable ;
1641+ }
1642+ logger .log (Level .WARNING , "Error deleting tunnel" , e );
16261643 }
16271644
1628- closeInputStream (connection );
1645+ InputStream stream = connection .getInputStream ();
1646+ return new BufferedInputStream (stream );
16291647 }
16301648
16311649 /**
0 commit comments