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 Summary
Modifier and TypeMethodDescriptionbuildError
(String error) Sets the error field of theErrorResponse
to the specified error message.buildMessage
(String message) Sets the message field of theErrorResponse
to the specified message.Sets the path field of theErrorResponse
to the specified path.buildStatusCode
(int code) Sets the status code field of theErrorResponse
to the specified code.buildTimestamp
(Date timestamp) Sets the timestamp field of theErrorResponse
to the specified date.make()
Builds and returns a new instance ofErrorResponse
using the fields set on this builder.reset()
Resets the builder's internal state to its initial values.
-
Method Details
-
buildTimestamp
Sets the timestamp field of theErrorResponse
to the specified date.- Parameters:
timestamp
- the date to set as the timestamp- Returns:
- the builder instance for method chaining
-
buildStatusCode
Sets the status code field of theErrorResponse
to the specified code.- Parameters:
code
- the HTTP status code to set- Returns:
- the builder instance for method chaining
-
buildError
Sets the error field of theErrorResponse
to the specified error message.- Parameters:
error
- the error message to set- Returns:
- the builder instance for method chaining
-
buildMessage
Sets the message field of theErrorResponse
to the specified message.- Parameters:
message
- the message to set- Returns:
- the builder instance for method chaining
-
buildPath
Sets the path field of theErrorResponse
to the specified path.- Parameters:
path
- the path to set- Returns:
- the builder instance for method chaining
-
reset
ErrorMessageBuilder reset()Resets the builder's internal state to its initial values.- Returns:
- the builder instance for method chaining
-
make
ErrorResponse make()Builds and returns a new instance ofErrorResponse
using the fields set on this builder.- Returns:
- a new instance of
ErrorResponse
-