Class ErrorResponseWriter

java.lang.Object
com.example.blogs.app.exception.ErrorResponseWriter

@Component public class ErrorResponseWriter extends Object
Writes standardized error responses to HTTP servlet responses.
  • 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 to
      request - the HTTP request that triggered the error
      objectMapper - Jackson ObjectMapper for JSON serialization
      status - HTTP status code for the error
      message - error message to include in response
      Throws:
      IOException - if writing to response fails