Skip to content

Commit 7889a69

Browse files
Merge pull request #241 from contentstack/staging
DX | 03-11-2025 | Release
2 parents a069e73 + 73ae158 commit 7889a69

24 files changed

+153
-59
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## v2.3.1
4+
5+
### Date: 03-Nov-2025
6+
7+
- Github issue fix
8+
- Improved error messages
9+
310
## v2.3.0
411

512
### Date: 29-Sep-2025

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>java</artifactId>
8-
<version>2.3.0</version>
8+
<version>2.3.1</version>
99
<packaging>jar</packaging>
1010
<name>contentstack-java</name>
1111
<description>Java SDK for Contentstack Content Delivery API</description>

src/main/java/com/contentstack/sdk/AssetLibrary.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ public AssetLibrary addParam(@NotNull String paramKey, @NotNull Object paramValu
179179
if (isValidKey(paramKey) && isValidValue(paramValue)) {
180180
urlQueries.put(paramKey, paramValue);
181181
} else {
182-
logger.warning("Invalid key or value");
182+
if (!isValidKey(paramKey)) {
183+
logger.warning(ErrorMessages.INVALID_PARAMETER_KEY);
184+
} else {
185+
logger.warning(ErrorMessages.INVALID_PARAMETER_VALUE);
186+
}
183187
}
184188
return this;
185189
}
@@ -310,9 +314,10 @@ public void getResultObject(List<Object> objects, JSONObject jsonObject, boolean
310314

311315
List<Asset> assets = new ArrayList<>();
312316

313-
// if (objects == null || objects.isEmpty()) {
314-
// System.out.println("Objects list is null or empty");
315-
// }
317+
if (objects == null || objects.isEmpty()) {
318+
logger.warning(ErrorMessages.MISSING_ASSETS_LIST);
319+
return;
320+
}
316321

317322
if (objects != null && !objects.isEmpty()) {
318323
for (Object object : objects) {
@@ -328,9 +333,9 @@ public void getResultObject(List<Object> objects, JSONObject jsonObject, boolean
328333
assets.add(asset);
329334
}
330335
}
331-
// else {
332-
// System.out.println("Object is not an instance of AssetModel");
333-
// }
336+
else {
337+
logger.warning(ErrorMessages.INVALID_OBJECT_TYPE_ASSET_MODEL);
338+
}
334339

335340
if (callback != null) {
336341
callback.onRequestFinish(ResponseType.NETWORK, assets);
@@ -351,7 +356,11 @@ public AssetLibrary where(String key, String value) {
351356
queryParams.put(key,value);
352357
urlQueries.put("query", queryParams);
353358
} else {
354-
throw new IllegalArgumentException("Invalid key or value");
359+
if (!isValidKey(key)) {
360+
throw new IllegalArgumentException(ErrorMessages.INVALID_PARAMETER_KEY);
361+
} else {
362+
throw new IllegalArgumentException(ErrorMessages.INVALID_PARAMETER_VALUE);
363+
}
355364
}
356365
return this;
357366
}

src/main/java/com/contentstack/sdk/AssetsModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public AssetsModel(JSONObject response) {
3131
List<?> assetsList = (List<?>) rawAssets;
3232
listResponse = new JSONArray(assetsList); // Convert to JSONArray
3333
} else if (rawAssets != null) {
34-
throw new IllegalArgumentException("Invalid type for 'assets' key: " + rawAssets.getClass().getName());
34+
throw new IllegalArgumentException(ErrorMessages.INVALID_ASSETS_TYPE);
3535
}
3636
if (listResponse != null) {
3737
listResponse.forEach(model -> {

src/main/java/com/contentstack/sdk/CSBackgroundTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected void checkHeader(@NotNull Map<String, Object> headers) {
9393
final Logger logger = Logger.getLogger("CSBackgroundTask");
9494
if (headers.size() == 0) {
9595
try {
96-
throw new IllegalAccessException("CSBackgroundTask Header Exception");
96+
throw new IllegalAccessException(ErrorMessages.MISSING_REQUEST_HEADERS);
9797
} catch (IllegalAccessException e) {
9898
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
9999
}

src/main/java/com/contentstack/sdk/CSHttpConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private String getParams(HashMap<String, Object> params) {
158158
urlParams += urlParams.equals("?") ? key + "=" + value : "&" + key + "=" + value;
159159
}
160160
} catch (Exception e1) {
161-
logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
161+
logger.log(Level.SEVERE, ErrorMessages.URL_PARAMETER_ENCODING_FAILED, e1);
162162
}
163163
}
164164
return urlParams;
@@ -187,7 +187,7 @@ public void send() {
187187
try {
188188
getService(url);
189189
} catch (IOException | JSONException e) {
190-
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
190+
logger.log(Level.SEVERE, ErrorMessages.URL_PARAMETER_ENCODING_FAILED, e);
191191
}
192192
}
193193

@@ -238,7 +238,7 @@ private void getService(String requestUrl) throws IOException {
238238
connectionRequest.onRequestFinished(CSHttpConnection.this);
239239
} catch (JSONException e) {
240240
// Handle non-JSON response
241-
setError("Invalid JSON response");
241+
setError(ErrorMessages.INVALID_JSON_RESPONSE);
242242
}
243243
} else {
244244
assert response.errorBody() != null;

src/main/java/com/contentstack/sdk/ContentType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ContentType {
4040
public JSONObject contentTypeData;
4141

4242
protected ContentType() throws IllegalAccessException {
43-
throw new IllegalAccessException("Can Not Access Private Modifier");
43+
throw new IllegalAccessException(ErrorMessages.DIRECT_INSTANTIATION_CONTENT_TYPE);
4444
}
4545

4646
protected ContentType(String contentTypeUid) {
@@ -158,7 +158,7 @@ public void fetch(@NotNull JSONObject params, final ContentTypesCallback callbac
158158
}
159159
params.put("environment", headers.get("environment"));
160160
if (contentTypeUid == null || contentTypeUid.isEmpty()) {
161-
throw new IllegalAccessException("contentTypeUid is required");
161+
throw new IllegalAccessException(ErrorMessages.CONTENT_TYPE_UID_REQUIRED);
162162
}
163163
fetchContentTypes(urlString, params, headers, callback);
164164
}

src/main/java/com/contentstack/sdk/ContentTypesModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void setJSON(JSONObject responseJSON) {
2929
try {
3030
this.response = new JSONObject((LinkedHashMap<?, ?>) responseJSON.get(ctKey));
3131
} catch (Exception e) {
32-
System.err.println("Error processing 'content_type': " + e.getMessage());
32+
System.err.println(ErrorMessages.INVALID_CONTENT_TYPE_DATA + " Technical details: " + e.getMessage());
3333
}
3434
}
3535
String ctListKey = "content_types";
@@ -44,14 +44,14 @@ public void setJSON(JSONObject responseJSON) {
4444
JSONObject jsonModel = new JSONObject((LinkedHashMap<?, ?>) model);
4545
objectList.add(jsonModel);
4646
} else {
47-
System.err.println("Invalid type in 'content_types' list. Expected LinkedHashMap.");
47+
System.err.println(ErrorMessages.INVALID_CONTENT_TYPES_LIST);
4848
}
4949
});
5050
}
5151
this.response = new JSONArray(objectList);
5252
this.responseJSONArray = new JSONArray(objectList);
5353
} catch (Exception e) {
54-
System.err.println("Error processing 'content_types': " + e.getMessage());
54+
System.err.println(ErrorMessages.INVALID_CONTENT_TYPE_DATA + " Technical details: " + e.getMessage());
5555
}
5656
}
5757
}

src/main/java/com/contentstack/sdk/Contentstack.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Contentstack {
1919

2020
// Modifier Protected
2121
protected Contentstack() throws IllegalAccessException {
22-
throw new IllegalAccessException("Can Not Access Private Modifier");
22+
throw new IllegalAccessException(ErrorMessages.DIRECT_INSTANTIATION_CONTENTSTACK);
2323
}
2424

2525
/**
@@ -88,13 +88,13 @@ private static void validateCredentials(String stackApiKey, String deliveryToken
8888
Objects.requireNonNull(environment, "Environment can not be null");
8989

9090
if (stackApiKey.isEmpty()) {
91-
throw new IllegalAccessException("API Key can not be empty");
91+
throw new IllegalAccessException(ErrorMessages.MISSING_API_KEY);
9292
}
9393
if (deliveryToken.isEmpty()) {
94-
throw new IllegalAccessException("Delivery Token can not be empty");
94+
throw new IllegalAccessException(ErrorMessages.MISSING_DELIVERY_TOKEN);
9595
}
9696
if (environment.isEmpty()) {
97-
throw new IllegalAccessException("Environment can not be empty");
97+
throw new IllegalAccessException(ErrorMessages.MISSING_ENVIRONMENT);
9898
}
9999
}
100100

src/main/java/com/contentstack/sdk/EntriesModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected EntriesModel(JSONObject responseJSON) {
3333
}
3434
} catch (Exception e) {
3535
Logger logger = Logger.getLogger(EntriesModel.class.getSimpleName());
36-
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
36+
logger.log(Level.SEVERE, ErrorMessages.ENTRIES_PROCESSING_FAILED, e);
3737
}
3838

3939
}

0 commit comments

Comments
 (0)