Skip to content

Commit 77d2b5d

Browse files
Merge pull request #86 from contentstack/fix/DX-3455-error-message-improve
Error message updates
2 parents 337dee7 + e417515 commit 77d2b5d

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Contentstack {
2727
private static Contentstack instance;
2828

2929
private Contentstack(Context context) {
30-
throw new IllegalStateException("Private constructor not allowed");
30+
throw new IllegalStateException(ErrorMessages.PRIVATE_CONSTRUCTOR_NOT_ALLOWED);
3131
}
3232

3333
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.contentstack.sdk;
2+
3+
/**
4+
* Contains all error messages used across the SDK.
5+
* Centralizing messages here makes it easier to maintain and update them.
6+
*/
7+
public final class ErrorMessages {
8+
private ErrorMessages() {
9+
throw new IllegalStateException("Utility class - do not instantiate");
10+
}
11+
12+
// Constructor related errors
13+
public static final String PRIVATE_CONSTRUCTOR_NOT_ALLOWED =
14+
"This class does not support private constructors. Use a public constructor to create an instance.";
15+
public static final String UTILITY_CLASS_INSTANTIATION =
16+
"This is a utility class and cannot be instantiated";
17+
public static final String NODE_TO_HTML_INSTANTIATION =
18+
"Failed to create an instance of NodeToHTML, you can directly access the methods of this class";
19+
20+
// Input validation errors
21+
public static final String NULL_OR_EMPTY_INPUT =
22+
"The input value cannot be null or empty. Provide a valid string to continue.";
23+
24+
// Network and parsing errors
25+
public static final String ENCODING_ERROR =
26+
"The system encountered an encoding issue while processing your request. Try again or contact support.";
27+
public static final String JSON_PARSING_ERROR =
28+
"We couldn't process the response due to a data formatting issue. Try again or contact support if the problem persists.";
29+
30+
// Cache related errors
31+
public static final String CACHE_INITIALIZATION_ERROR =
32+
"Failed to initialize cache. The application will continue without caching.";
33+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* <code>
1414
* public void processInput(String input) throws InvalidInputException {
1515
* if (input == null || input.isEmpty()) {
16-
* throw new InvalidInputException("Input cannot be null or empty");
16+
* throw new InvalidInputException(ErrorMessages.NULL_OR_EMPTY_INPUT);
1717
* }
1818
* // Process the input here
1919
* }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
2424
String jsonString = new String(response.data, "UTF-8");
2525
return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
2626
} catch (UnsupportedEncodingException e) {
27-
return Response.error(new ParseError(e));
27+
return Response.error(new ParseError(new UnsupportedEncodingException(ErrorMessages.ENCODING_ERROR)));
2828
} catch (JSONException je) {
29-
return Response.error(new ParseError(je));
29+
return Response.error(new ParseError(new JSONException(ErrorMessages.JSON_PARSING_ERROR)));
3030
}
3131
}
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class NodeToHTML {
66
private NodeToHTML() {
7-
throw new IllegalStateException("Could not create instance of NodeToHTML");
7+
throw new IllegalStateException(ErrorMessages.NODE_TO_HTML_INSTANTIATION);
88
}
99
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
1010
String text = nodeText.optString("text");

0 commit comments

Comments
 (0)