Commit Graph

4 Commits

Author SHA1 Message Date
Balázs Szücs
43345021bf
refactor(exceptions): RFC 7807 Problem Details, ResourceBundle i18n, and error factory pattern (#4791)
# 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 `GlobalExceptionHandler` with tailored
handlers for password-protected files, corruption, validation, and
Spring framework errors. Every response includes localized `errorCode`,
contextual hints, actionable guidance, timestamps, and request paths.

**Key improvements:**
- Unified error handling prevents inconsistent response formats across
services
- Localized error messages support multiple languages at runtime
- Error context (hints, actionRequired field) improves user experience
- Structured metadata enables programmatic error handling on client side

Reference:
https://www.baeldung.com/spring-boot-return-errors-problemdetail

### Exception Handling

- Centralized all exception handling in `GlobalExceptionHandler` with
specific handlers for password protection, file corruption, validation
errors, and Spring exceptions
- Refactored `ExceptionUtils` to generate consistent `ProblemDetail`
responses with error metadata
- Introduced `ErrorCode` enum to centralize error identification and
metadata (supports localization)
- Added helper methods for creating standardized exceptions across
services

### Implementation Details

- **Replaced generic exceptions** with `ExceptionUtils` methods across
utility classes (`CbrUtils`, `CbzUtils`, `PdfToCbrUtils`,
`EmlProcessingUtils`, `ImageProcessingUtils`) for consistent error
handling of invalid formats, empty files, and missing resources
- **Improved method signatures** in `JobExecutorService` and
`AutoJobAspect` by explicitly declaring thrown exceptions
- **Refined job execution error handling** by removing unnecessary catch
blocks in synchronous execution, allowing exceptions to propagate to the
centralized handler
- **Enhanced error messages** for unsupported formats (e.g., RAR5
limitations, PDF-to-CBR constraints) with clearer user guidance

### Response Format

All errors now include:
- `errorCode`: Machine-readable error identifier (localized at runtime)
- `title`: Localized error title
- `detail`: Context-specific error message
- `hints`: Array of actionable suggestions
- `actionRequired`: Boolean flag indicating if user action is needed
- `timestamp`: Error occurrence time
- `path`: Request path where error occurred

**Error examples shown in PR include:** corrupt files, invalid
passwords, unsupported formats (RAR5), missing images, OOM conditions,
and invalid HTML

### Why This Change

- Eliminates ad-hoc error handling patterns scattered across services
- Provides actionable guidance instead of technical stack traces
- Supports error messages in multiple languages without code changes
- Aligns with RFC 7807, improving API interoperability
- Error context reduces time to diagnose issues


### 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:
<img width="1912" height="568" alt="image"
src="https://github.com/user-attachments/assets/fc6c9dd6-4929-49ab-8e44-bd79c59d875a"
/>
Password-protected file (invalid password):
<img width="1912" height="757" alt="image"
src="https://github.com/user-attachments/assets/31632271-8b2f-45c5-ad4a-dff51e085ea0"
/>
Unsupported RAR:
<img width="1912" height="636" alt="image"
src="https://github.com/user-attachments/assets/d13cd521-4b07-4399-b97b-4defa842fc05"
/>
No images in RAR/ZIP:
<img width="1912" height="642" alt="image"
src="https://github.com/user-attachments/assets/f02999ed-7a56-4e34-9a95-df50c77012cf"
/>

OOM:
<img width="1912" height="714" alt="image"
src="https://github.com/user-attachments/assets/3aaf491a-fe42-4831-b905-a4d248e34860"
/>
Invalid html (on the html to pdf endpoint)
<img width="1912" height="577" alt="image"
src="https://github.com/user-attachments/assets/584ec7c8-f14c-4eb1-a6b2-cf7812ae8f0a"
/>

GS conversion fail:
<img width="1912" height="674" alt="image"
src="https://github.com/user-attachments/assets/8504a876-75e6-40ef-891b-4ee2b3bbdb0a"
/>

 


<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
2025-11-21 21:08:56 +00:00
Ludy
03f184ab2b
chore(cucumber): add create_pdf_with_black_boxes and convert-pdf-to-image outline; remove duplicate split-pdf-by-sections (#3937)
# Description of Changes

- **What was changed**  
- Introduced `create_pdf_with_black_boxes` helper function in
`environment.py` for generating test PDFs with occluded content.
- Added **Scenario Outline: Convert PDF to image** to
`conversion.feature` to validate PDF→image conversion workflows.
- Removed the duplicate **Scenario Outline: split-pdf-by-sections with
different parameters** from `general.feature`.

- **Why the change was made**  
- To enable testing of blacked-out content scenarios and ensure our
suite covers image conversion.
- To eliminate redundant tests and keep the feature files DRY and
maintainable.

---

## Checklist

### General

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
2025-07-14 12:05:17 +01:00
Ludy
52f09f1840
Improve Type Safety and OpenAPI Schema for PDF API Controllers and Models (#3470)
# Description of Changes

- **What was changed**  
- Updated controller methods to use strongly‐typed primitives (`int`,
`long`, `boolean`) instead of `String` for numeric and boolean
parameters, eliminating calls to `Integer.parseInt`/`Long.parseLong` and
improving null‐safety (`Boolean.TRUE.equals(...)`).
- Enhanced all API request model classes with richer Swagger/OpenAPI
annotations: added `requiredMode`, `defaultValue`, `allowableValues`,
`format`, `pattern`, and tightened schema descriptions for all fields.
- Refactored HTML form templates for “Remove Blank Pages” to include
`min`, `max`, and `step` attributes on numeric inputs, matching the
updated validation rules.

- **Why the change was made**  
- **Type safety & robustness**: Shifting from `String` to native types
prevents runtime parsing errors, simplifies controller logic, and makes
default values explicit.
- **Better API documentation & validation**: Enriching the Swagger
annotations ensures generated docs accurately reflect required fields,
default values, and permitted ranges, which improves client code
generation and developer experience.
- **Consistency across codebase**: Aligning all request models and
controllers enforces a uniform coding style and reduces bugs.

#3406

---

## Checklist

### General

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-05-16 12:23:01 +01:00
Anthony Stirling
dab6613f1b
Test cleanup, JVM GC and api (#2787)
# Description of Changes

Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.

---------

Co-authored-by: a <a>
2025-01-26 13:10:16 +00:00