Class ErrorPageUtils

java.lang.Object
com.endurancetrio.app.common.utils.ErrorPageUtils

public final class ErrorPageUtils extends Object
Utility class with shared methods for building and rendering error pages.

Centralizes logic that is common between EnduranceTrioErrorController and EnduranceTrioExceptionHandlerWeb to avoid code duplication.

  • Method Details

    • errorView

      public static String errorView(int statusCode)
      Resolves an HTTP status code to the corresponding error view name.
      Parameters:
      statusCode - the HTTP status code (e.g. 403, 404, 500)
      Returns:
      the Thymeleaf view name for the error page (e.g. error/403)
    • createErrorPageMetadata

      public static PageMetadata createErrorPageMetadata(int statusCode, @NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull Locale locale, @NonNull MessageService messageService, @NonNull AppProperties appProperties)
      Creates a PageMetadata object for an error page using the appropriate i18n message keys based on the HTTP status code.
      Parameters:
      statusCode - the HTTP status code (e.g. 403, 404, 500)
      request - the current HTTP request, used for URL construction
      locale - the resolved locale for i18n messages
      messageService - the service used to retrieve i18n messages
      appProperties - the application properties for metadata configuration
      Returns:
      a fully populated PageMetadata instance
    • buildErrorModelAndView

      public static org.springframework.web.servlet.ModelAndView buildErrorModelAndView(@NonNull org.springframework.http.HttpStatus status, @NonNull String message, List<ErrorDTO> errors, @NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull MessageService messageService, @NonNull AppProperties appProperties)
      Builds a complete ModelAndView for an error page. Resolves the locale, creates the page metadata, and populates the model with standard error attributes.
      Parameters:
      status - the HTTP status of the response
      message - the human-readable error message
      errors - an optional list of structured ErrorDTO objects, may be null
      request - the current HTTP request
      messageService - the service used to retrieve i18n messages
      appProperties - the application properties for metadata configuration
      Returns:
      a fully initialised ModelAndView ready for rendering