6
6
package com .magento .idea .magento2uct .packages ;
7
7
8
8
import java .io .BufferedReader ;
9
+ import java .io .IOException ;
9
10
import java .io .InputStreamReader ;
10
11
import java .net .HttpURLConnection ;
11
12
import java .net .URL ;
19
20
public enum SupportedVersion {
20
21
;
21
22
private final String version ;
23
+ private static final Integer SUCCESS_CODE = 200 ;
22
24
23
25
SupportedVersion (final String version ) {
24
26
this .version = version ;
@@ -69,9 +71,9 @@ public static List<String> getSupportedVersions() {
69
71
* from a predefined URL and parses it into a list of version strings.
70
72
*
71
73
* @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
73
75
*/
74
- public static List <String > fetchSupportedVersions () throws Exception { //NOPMD - suppressed SignatureDeclareThrowsException
76
+ public static List <String > fetchSupportedVersions () throws IOException {
75
77
final String url = "https://repo.packagist.org/p2/magento/community-edition.json" ;
76
78
final List <String > versions = new ArrayList <>();
77
79
@@ -82,8 +84,8 @@ public static List<String> fetchSupportedVersions() throws Exception { //NOPMD -
82
84
connection .setRequestMethod ("GET" );
83
85
connection .setRequestProperty ("Accept" , "application/json" );
84
86
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
87
89
"Failed to fetch data, HTTP response code: " + connection .getResponseCode ()
88
90
);
89
91
}
@@ -94,7 +96,7 @@ public static List<String> fetchSupportedVersions() throws Exception { //NOPMD -
94
96
) {
95
97
final StringBuilder response = new StringBuilder ();
96
98
String line ;
97
- while ((line = reader .readLine ()) != null ) { //NOPMD - suppressed AssignmentInOperand
99
+ while ((line = reader .readLine ()) != null ) {//NOPMD - suppressed AssignmentInOperand
98
100
response .append (line );
99
101
}
100
102
0 commit comments