Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Contentstack {
private static Contentstack instance;

private Contentstack(Context context) {
throw new IllegalStateException("Private constructor not allowed");
throw new IllegalStateException(ErrorMessages.PRIVATE_CONSTRUCTOR_NOT_ALLOWED);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.contentstack.sdk;

/**
* Contains all error messages used across the SDK.
* Centralizing messages here makes it easier to maintain and update them.
*/
public final class ErrorMessages {
private ErrorMessages() {
throw new IllegalStateException("Utility class - do not instantiate");
}

// Constructor related errors
public static final String PRIVATE_CONSTRUCTOR_NOT_ALLOWED =
"This class does not support private constructors. Use a public constructor to create an instance.";
public static final String UTILITY_CLASS_INSTANTIATION =
"This is a utility class and cannot be instantiated";
public static final String NODE_TO_HTML_INSTANTIATION =
"Failed to create an instance of NodeToHTML, you can directly access the methods of this class";

// Input validation errors
public static final String NULL_OR_EMPTY_INPUT =
"The input value cannot be null or empty. Provide a valid string to continue.";

// Network and parsing errors
public static final String ENCODING_ERROR =
"The system encountered an encoding issue while processing your request. Try again or contact support.";
public static final String JSON_PARSING_ERROR =
"We couldn't process the response due to a data formatting issue. Try again or contact support if the problem persists.";

// Cache related errors
public static final String CACHE_INITIALIZATION_ERROR =
"Failed to initialize cache. The application will continue without caching.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* <code>
* public void processInput(String input) throws InvalidInputException {
* if (input == null || input.isEmpty()) {
* throw new InvalidInputException("Input cannot be null or empty");
* throw new InvalidInputException(ErrorMessages.NULL_OR_EMPTY_INPUT);
* }
* // Process the input here
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
String jsonString = new String(response.data, "UTF-8");
return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
return Response.error(new ParseError(new UnsupportedEncodingException(ErrorMessages.ENCODING_ERROR)));
} catch (JSONException je) {
return Response.error(new ParseError(je));
return Response.error(new ParseError(new JSONException(ErrorMessages.JSON_PARSING_ERROR)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class NodeToHTML {
private NodeToHTML() {
throw new IllegalStateException("Could not create instance of NodeToHTML");
throw new IllegalStateException(ErrorMessages.NODE_TO_HTML_INSTANTIATION);
}
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
String text = nodeText.optString("text");
Expand Down
Loading