@@ -590,6 +590,10 @@ private static String doHTTP(String url, String method, @Nullable String request
590590 }
591591
592592 LOGGER .trace ("{} {} HTTP/1.1 {TCP} {}" , method , url , request == null ? "" : ">> " + request );
593+ if (status > 299 ) {
594+ LOGGER .debug ("HTTP/1.1 {} {}" , status , connection .getResponseMessage ());
595+ throw new IOException ("HTTP error " + status );
596+ }
593597 try (InputStream in = connection .getInputStream ()) {
594598 String response = new String (in .readAllBytes (), StandardCharsets .UTF_8 );
595599 LOGGER .trace ("HTTP/1.1 {} {} << {}" , status , connection .getResponseMessage (), response );
@@ -643,6 +647,10 @@ private static String doHTTPS(String url, String method, @Nullable String reques
643647 int status = connection .getResponseCode ();
644648
645649 LOGGER .trace ("{} {} HTTP/1.1 {TLS} {}" , method , url , request == null ? "" : ">> " + request );
650+ if (status > 299 ) {
651+ LOGGER .debug ("HTTP/1.1 {} {}" , status , connection .getResponseMessage ());
652+ throw new IOException ("HTTP error " + status );
653+ }
646654 try (InputStream in = connection .getInputStream ()) {
647655 String response = new String (in .readAllBytes (), StandardCharsets .UTF_8 );
648656 LOGGER .trace ("HTTP/1.1 {} {} << {}" , status , connection .getResponseMessage (), response );
@@ -743,11 +751,10 @@ public static boolean isClip2Supported(String hostName) throws IOException {
743751 private static final Pattern IPV4_PATTERN = Pattern .compile (IPV4_REGEX );
744752
745753 /**
746- * Static reference to the most recently created instance of this class, which allows the static
747- * doHTTPS() method to use the instance SSL context if available, otherwise fallback to the static
748- * TRUST_ALL_CONTEXT. This is necessary because the doHTTP() method is used for the initial
749- * registration call before the instance is created and the SSL context is configured, but we
750- * want to use the instance SSL context for all subsequent calls.
754+ * In case the class has been instantiated we use the instance SSL context for the static doHTTP() method,
755+ * otherwise we fall back to a static trust all SSL context. This allows the static doHTTP() method to be
756+ * used for the initial registration call before the instance is created and the SSL context is configured,
757+ * and to use the instance SSL context for all subsequent calls.
751758 */
752759 private static final SSLContext TRUST_ALL_CONTEXT = createTrustAllSslContext ();
753760 private final SSLContext hueContext ;
@@ -1461,7 +1468,7 @@ public void testConnectionState() throws HttpUnauthorizedException, ApiException
14611468 return config .getUpdateStatusMap ();
14621469 }
14631470 } catch (IOException e ) {
1464- LOGGER .debug ("getUpdateStatus () error '{}'" , e .getMessage ());
1471+ LOGGER .debug ("getUpdateStatusMap () error '{}'" , e .getMessage ());
14651472 }
14661473 return new HashMap <>();
14671474 }
0 commit comments