Interface ErrorMessageBuilder

All Known Implementing Classes:
ErrorMessageBuilderImpl

public interface ErrorMessageBuilder

An interface used to implement the builder pattern for building an ErrorResponse. The ErrorMessageBuilder provides methods for building the various fields of an ErrorResponse object, allowing for a more flexible and readable way to create instances of this class. It also provides a method to reset the builder's internal state and start over.

Example usage:


  ErrorMessageBuilder builder = new MyErrorMessageBuilder();

  ErrorResponse errorResponse = builder
  .buildTimestamp(new Date())
  .buildStatusCode(404)
  .buildError("Not Found")
  .buildMessage("The requested resource was not found.")
  .buildPath("/api/users")
  .make();
  
Note that the order in which the methods are called does not matter, as long as all necessary fields are set before calling the make() method to create the ErrorResponse object.
  • Method Details

    • buildTimestamp

      ErrorMessageBuilder buildTimestamp(Date timestamp)
      Sets the timestamp field of the ErrorResponse to the specified date.
      Parameters:
      timestamp - the date to set as the timestamp
      Returns:
      the builder instance for method chaining
    • buildStatusCode

      ErrorMessageBuilder buildStatusCode(int code)
      Sets the status code field of the ErrorResponse to the specified code.
      Parameters:
      code - the HTTP status code to set
      Returns:
      the builder instance for method chaining
    • buildError

      ErrorMessageBuilder buildError(String error)
      Sets the error field of the ErrorResponse to the specified error message.
      Parameters:
      error - the error message to set
      Returns:
      the builder instance for method chaining
    • buildMessage

      ErrorMessageBuilder buildMessage(String message)
      Sets the message field of the ErrorResponse to the specified message.
      Parameters:
      message - the message to set
      Returns:
      the builder instance for method chaining
    • buildPath

      ErrorMessageBuilder buildPath(String path)
      Sets the path field of the ErrorResponse to the specified path.
      Parameters:
      path - the path to set
      Returns:
      the builder instance for method chaining
    • reset

      Resets the builder's internal state to its initial values.
      Returns:
      the builder instance for method chaining
    • make

      Builds and returns a new instance of ErrorResponse using the fields set on this builder.
      Returns:
      a new instance of ErrorResponse