-
Notifications
You must be signed in to change notification settings - Fork 5.9k
refactor(exceptions): RFC 7807 Problem Details, ResourceBundle i18n, and error factory pattern #4791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(exceptions): RFC 7807 Problem Details, ResourceBundle i18n, and error factory pattern #4791
Conversation
…d clarity and maintainability. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
# Conflicts: # app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java # app/common/src/test/java/stirling/software/common/service/JobExecutorServiceTest.java # app/core/src/test/java/stirling/software/SPDF/controller/api/converters/PdfToCbzUtilsTest.java
…llers and services for improved consistency and localization. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…rors and improve memory safety. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…ing detailed diagnostics, and refining exception messages for better clarity and context. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…ion utility methods** - Updated `testCreatePdfCorruptedExceptionWithoutContext` to assert message content and properly pass a `null` context. - Removed redundant tests: `testCreateFileNotFoundException`, `testCreateInvalidComparatorException`, `testCreateCompressionOptionsException`, and `testCreateQpdfCompressionException`. - Enhanced `testCreateInvalidArgumentExceptionSingle` to validate message content for both argument and value. - Adjusted `INVALID_ARGUMENT` error message format for clarity. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…mproved performance and code maintainability** - Replaced `String`-based hashes with `ImageIdentity` class for better accuracy in identifying unique images. - Refactored `compressImagesInPDF` to streamline compression workflow and leverage new helper methods. - Improved method visibility, added static modifiers, and reduced code duplication across compression utilities. - Enhanced hashing logic by considering additional image properties like filters, decode parameters, and metadata. - Simplified and extended error handling for various edge cases, ensuring safer PDF processing. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…or error handling** - Updated all exception response methods to explicitly set `APPLICATION_PROBLEM_JSON` as the content type. - Ensured consistency across status codes and exception scenarios for improved client compatibility. - Simplified and enhanced readability of response entity construction. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…y in exception utilities - Added reusable regex patterns in `RegexPatternUtils` for line separator and leading asterisks whitespace removal. - Replaced inline regex logic with `RegexPatternUtils` patterns for better maintainability. - Improved memory usage and readability in key generation logic with `StringBuilder`. - Removed redundant methods and streamlined utility functionality for better clarity. - Converted `GhostscriptErrorInfo` to a `record` for immutability and reduced boilerplate. - Adjusted method visibility and modifiers in `GlobalExceptionHandler` for consistency. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
- Added new `ErrorCodeProvider` interface for consistent error code support across exceptions. - Consolidated exception-related constants into `GlobalExceptionHandler` for better maintainability. - Updated error response methods to standardize content and REST compatibility. - Improved logging for all exception handlers using a unified `logException` method. - Refactored and removed redundant code, including outdated factory methods for exceptions. - Introduced helper methods for handling hints and localized error messages. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…ode in tests - Fixed typo in the `ExceptionUtils` class documentation for better clarity. - Updated the expected response code in the Cucumber test scenario from 422 to 400 to reflect correct behavior. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
…maintainability - Added filename-based validation to the `isZip` method for improved filtering, especially for `.cbz` files. - Overloaded `isZip` to support both data and filename parameters for better usability. - Updated all existing ZIP-check references to use the new overloaded method, ensuring backward compatibility. - Improved code readability and ensured consistent handling of ZIP-like files during the unzipping process. Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a comprehensive RFC 7807 Problem Details error handling system with internationalized messages, replacing the previous error handling approach. The changes standardize error responses across the application and provide better user-facing error messages with actionable hints.
- Introduces
GlobalExceptionHandlerfor centralized exception handling with RFC 7807 Problem Details responses - Expands
ExceptionUtilswith typed exception classes, error codes, and helper methods for consistent error creation - Updates all controllers and services to use typed exceptions instead of generic
IllegalArgumentExceptionandIOException - Adds extensive internationalized error messages with hints and action-required text in
messages_en_GB.properties - Updates frontend JavaScript to parse and display structured error messages from Problem Details responses
Reviewed Changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
GlobalExceptionHandler.java |
New centralized exception handler implementing RFC 7807 Problem Details with error codes, hints, and localized messages |
ExceptionUtils.java |
Major expansion with typed exception classes, error code enum, OOM handling utilities, and Ghostscript error detection |
messages_en_GB.properties |
Extensive new error messages, titles, hints, and action-required text for all error codes |
PasswordController.java |
Updated to catch and wrap password errors with typed exceptions |
examples.feature |
Test expectation changed from 500 to 400 for wrong password scenario |
PdfToCbzUtilsTest.java |
Updated test to match new error message format |
| Multiple controller files | Updated to use ExceptionUtils factory methods instead of raw exception constructors |
| Frontend JS files | Enhanced error handling to parse Problem Details JSON and display user-friendly messages with hints |
application.properties |
Enabled RFC 7807 Problem Details support |
JobExecutorService.java |
Removed inline error handling to let GlobalExceptionHandler process exceptions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/service/JobExecutorService.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/ExceptionUtils.java
Show resolved
Hide resolved
… fields
- Replaced `@Getter` with `@Getter(onMethod_ = {@OverRide})` for `BaseAppException` and `BaseValidationException`.
- Ensured alignment with `ErrorCodeProvider` interface implementation.
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
Description of Changes
Implemented RFC 7807 problem-details standard to provide consistent, structured error responses across the application. All exceptions now flow through a centralized
GlobalExceptionHandlerwith tailored handlers for password-protected files, corruption, validation, and Spring framework errors. Every response includes localizederrorCode, contextual hints, actionable guidance, timestamps, and request paths.Key improvements:
Reference: https://www.baeldung.com/spring-boot-return-errors-problemdetail
Exception Handling
GlobalExceptionHandlerwith specific handlers for password protection, file corruption, validation errors, and Spring exceptionsExceptionUtilsto generate consistentProblemDetailresponses with error metadataErrorCodeenum to centralize error identification and metadata (supports localization)Implementation Details
ExceptionUtilsmethods across utility classes (CbrUtils,CbzUtils,PdfToCbrUtils,EmlProcessingUtils,ImageProcessingUtils) for consistent error handling of invalid formats, empty files, and missing resourcesJobExecutorServiceandAutoJobAspectby explicitly declaring thrown exceptionsResponse Format
All errors now include:
errorCode: Machine-readable error identifier (localized at runtime)title: Localized error titledetail: Context-specific error messagehints: Array of actionable suggestionsactionRequired: Boolean flag indicating if user action is neededtimestamp: Error occurrence timepath: Request path where error occurredError examples shown in PR include: corrupt files, invalid passwords, unsupported formats (RAR5), missing images, OOM conditions, and invalid HTML
Why This Change
Error sample (note the unformatted JSON is NOT visible by default but for presenting purposes I clicked on show stack on each error. By default only error banner (top part of error) visible)
Corrupt file:




Password-protected file (invalid password):
Unsupported RAR:
No images in RAR/ZIP:
OOM:


Invalid html (on the html to pdf endpoint)
GS conversion fail:

Checklist
General
Documentation
UI Changes (if applicable)
Testing (if applicable)