66package com .magento .idea .magento2uct .packages ;
77
88import java .io .BufferedReader ;
9+ import java .io .IOException ;
910import java .io .InputStreamReader ;
1011import java .net .HttpURLConnection ;
1112import java .net .URL ;
1920public enum SupportedVersion {
2021 ;
2122 private final String version ;
23+ private static final Integer SUCCESS_CODE = 200 ;
2224
2325 SupportedVersion (final String version ) {
2426 this .version = version ;
@@ -69,9 +71,9 @@ public static List<String> getSupportedVersions() {
6971 * from a predefined URL and parses it into a list of version strings.
7072 *
7173 * @return List[String] containing supported version strings
72- * @throws Exception if an error occurs during HTTP connection or JSON parsing
74+ * @throws IOException if an error occurs during HTTP connection or JSON parsing
7375 */
74- public static List <String > fetchSupportedVersions () throws Exception { //NOPMD - suppressed SignatureDeclareThrowsException
76+ public static List <String > fetchSupportedVersions () throws IOException {
7577 final String url = "https://repo.packagist.org/p2/magento/community-edition.json" ;
7678 final List <String > versions = new ArrayList <>();
7779
@@ -82,8 +84,8 @@ public static List<String> fetchSupportedVersions() throws Exception { //NOPMD -
8284 connection .setRequestMethod ("GET" );
8385 connection .setRequestProperty ("Accept" , "application/json" );
8486
85- if (connection .getResponseCode () != 200 ) { //NOPMD - suppressed AvoidLiteralsInIfCondition
86- throw new Exception ( //NOPMD - suppressed AvoidThrowingRawExceptionTypes
87+ if (connection .getResponseCode () != SUCCESS_CODE ) {
88+ throw new IOException ( //NOPMD - suppressed AvoidThrowingRawExceptionTypes
8789 "Failed to fetch data, HTTP response code: " + connection .getResponseCode ()
8890 );
8991 }
@@ -94,7 +96,7 @@ public static List<String> fetchSupportedVersions() throws Exception { //NOPMD -
9496 ) {
9597 final StringBuilder response = new StringBuilder ();
9698 String line ;
97- while ((line = reader .readLine ()) != null ) { //NOPMD - suppressed AssignmentInOperand
99+ while ((line = reader .readLine ()) != null ) {//NOPMD - suppressed AssignmentInOperand
98100 response .append (line );
99101 }
100102
0 commit comments