Class ErrorPageUtils
java.lang.Object
com.endurancetrio.app.common.utils.ErrorPageUtils
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 Summary
Modifier and TypeMethodDescriptionstatic org.springframework.web.servlet.ModelAndViewbuildErrorModelAndView(@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 completeModelAndViewfor an error page.static PageMetadatacreateErrorPageMetadata(int statusCode, @NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull Locale locale, @NonNull MessageService messageService, @NonNull AppProperties appProperties) Creates aPageMetadataobject for an error page using the appropriate i18n message keys based on the HTTP status code.static StringerrorView(int statusCode) Resolves an HTTP status code to the corresponding error view name.
-
Method Details
-
errorView
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 aPageMetadataobject 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 constructionlocale- the resolved locale for i18n messagesmessageService- the service used to retrieve i18n messagesappProperties- the application properties for metadata configuration- Returns:
- a fully populated
PageMetadatainstance
-
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 completeModelAndViewfor 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 responsemessage- the human-readable error messageerrors- an optional list of structuredErrorDTOobjects, may be nullrequest- the current HTTP requestmessageService- the service used to retrieve i18n messagesappProperties- the application properties for metadata configuration- Returns:
- a fully initialised
ModelAndViewready for rendering
-