java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.github.venkateshamurthy.enums.examples.CommonRTE
All Implemented Interfaces:
Serializable

public class CommonRTE extends RuntimeException implements Serializable
CommonRTE is a unified runtime exception class that can be used across the project to encapsulate error information in a structured and consistent format.

This class extends RuntimeException and adds contextual fields such as:

  • code - Application or domain-specific error code
  • detailedMessage - Detailed, formatted explanation of the error
  • timeStamp - UTC timestamp when the error was created
  • httpStatus - The HttpStatus representing the error category

The class supports message formatting with templates, placeholder substitution, and structured logging to simplify debugging and monitoring.

Example usage:


 throw new CommonRTE(FaultCode.CREDENTIAL_MISSING,
     "Missing or invalid credential ID: {}", request.getCredentialId())
     .setHttpStatus(HttpStatus.BAD_REQUEST)
     .logInfo();
 

Another example: *


  * throw FaultCodes.CREDENTIAL_MISSING.toCommonRTE(
  *     "Missing or invalid credential ID: {}", request.getCredentialId())
  *     .setHttpStatus(HttpStatus.BAD_REQUEST)
  *     .logInfo();
  * 
Since:
1.0
Author:
venkateshamurthy
See Also:
  • Field Details

  • Constructor Details

    • CommonRTE

      public CommonRTE(String message)
      Constructs a new CommonRTE with the specified message. Automatically sets the timestamp to current UTC time.
      Parameters:
      message - the exception message
    • CommonRTE

      public CommonRTE(String message, Throwable cause)
      Constructs a new CommonRTE with the specified message and cause. Automatically sets the timestamp to current UTC time.
      Parameters:
      message - the exception message
      cause - the underlying cause of this exception
  • Method Details

    • detailedMessage

      public CommonRTE detailedMessage(String template, Object... values)
      Sets the detailed message by substituting positional placeholders ("{}") in the given template.
      Parameters:
      template - the message template
      values - values to replace in template
      Returns:
      this instance for fluent chaining
    • setDetailedMessage

      public CommonRTE setDetailedMessage(String template, Map<String,Object> values)
      Sets the detailed message by replacing named placeholders in the form of {key}.

      Example:

      
       exception.setDetailedMessage("Error in {module} at {time}", Map.of("module", "Auth", "time", "12:00 UTC"));
       
      Parameters:
      template - the message template with named placeholders
      values - the key-value pairs for substitution
      Returns:
      this instance for fluent chaining
    • formatDetailedMessage

      public CommonRTE formatDetailedMessage(MessageFormat template, Object... values)
      Sets the detailed message using a MessageFormat instance for advanced message formatting.
      Parameters:
      template - the MessageFormat instance
      values - the argument values
      Returns:
      this instance for fluent chaining
    • logInfo

      public CommonRTE logInfo()
      Logs this exception’s summary at INFO level, including error code, timestamp, and details.
      Returns:
      this instance for fluent chaining
    • logDebug

      public CommonRTE logDebug()
      Logs this exception at DEBUG level (though implemented as INFO here for visibility), including message, code, timestamp, details, and HTTP status.
      Returns:
      this instance for fluent chaining