Class ErrorResponseCreator
java.lang.Object
com.bobocode.bring.web.servlet.error.ErrorResponseCreator
The ErrorResponseCreator class is responsible for creating instances of ErrorResponse.
It provides methods to prepare error responses with various configurations.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondefaultErrorResponse
(Throwable e, Boolean withStackTrace) Prepares a default error response for internal server errors.private String
getMessage
(ResponseStatus responseStatus, Throwable throwable) Retrieves the error message based on the provided ResponseStatus and Throwable.private String
getStackTrace
(Throwable throwable, Boolean withStackTrace) Returns the stack trace as a string based on the specified flag.prepareErrorResponse
(ResponseStatus responseStatus, Throwable throwable, Boolean withStackTrace) Prepares a customized error response based on the provided parameters.private String
prepareStackTrace
(Throwable throwable) Prepares the stack trace as a string.
-
Constructor Details
-
ErrorResponseCreator
public ErrorResponseCreator()
-
-
Method Details
-
prepareErrorResponse
public ErrorResponse prepareErrorResponse(ResponseStatus responseStatus, Throwable throwable, Boolean withStackTrace) Prepares a customized error response based on the provided parameters.- Parameters:
responseStatus
- The response status to be included in the error response.throwable
- The Throwable object associated with the error, providing additional details.withStackTrace
- A flag indicating whether to include the stack trace in the error response.- Returns:
- An ErrorResponse object containing the prepared error details.
-
defaultErrorResponse
Prepares a default error response for internal server errors.- Parameters:
e
- The Throwable object representing the internal server error.withStackTrace
- A flag indicating whether to include the stack trace in the error response.- Returns:
- An ErrorResponse object containing the default internal server error details.
-
getStackTrace
Returns the stack trace as a string based on the specified flag.- Parameters:
throwable
- The Throwable object from which the stack trace is extracted.withStackTrace
- A flag indicating whether to include the stack trace.- Returns:
- The stack trace as a string if withStackTrace is true, otherwise null.
-
prepareStackTrace
Prepares the stack trace as a string.- Parameters:
throwable
- The Throwable object from which the stack trace is extracted.- Returns:
- The stack trace as a string.
-
getMessage
Retrieves the error message based on the provided ResponseStatus and Throwable.- Parameters:
responseStatus
- The ResponseStatus object representing the error status.throwable
- The Throwable object associated with the error.- Returns:
- The error message, either from ResponseStatus or Throwable.
-