Package com.example.blogs.app.exception
Class ErrorResponseWriter
java.lang.Object
com.example.blogs.app.exception.ErrorResponseWriter
Writes standardized error responses to HTTP servlet responses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidwriteErrorResponse(jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.http.HttpServletRequest request, com.fasterxml.jackson.databind.ObjectMapper objectMapper, HttpStatus status, String message) Writes a formatted error response to the HTTP response output stream.
-
Constructor Details
-
ErrorResponseWriter
public ErrorResponseWriter()
-
-
Method Details
-
writeErrorResponse
public void writeErrorResponse(jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.http.HttpServletRequest request, com.fasterxml.jackson.databind.ObjectMapper objectMapper, HttpStatus status, String message) throws IOException Writes a formatted error response to the HTTP response output stream. Sets appropriate HTTP status code and content type for JSON response.- Parameters:
response- the HTTP response to write torequest- the HTTP request that triggered the errorobjectMapper- Jackson ObjectMapper for JSON serializationstatus- HTTP status code for the errormessage- error message to include in response- Throws:
IOException- if writing to response fails
-