Skip to content

Unwrap HandlerFailedException and add AccessDeniedException to be caught#19

Merged
stixx merged 1 commit into
mainfrom
handler-exceptions
Apr 11, 2026
Merged

Unwrap HandlerFailedException and add AccessDeniedException to be caught#19
stixx merged 1 commit into
mainfrom
handler-exceptions

Conversation

@stixx
Copy link
Copy Markdown
Owner

@stixx stixx commented Apr 11, 2026

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved error handling for asynchronous operations by properly unwrapping and processing underlying exceptions.
    • Enhanced security exception detection to correctly respond to access denial scenarios.
  • Tests

    • Added test coverage for messenger exception unwrapping behavior.
    • Added test coverage for security-layer exception handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7e9f409f-541c-45db-807e-b52473126496

📥 Commits

Reviewing files that changed from the base of the PR and between b29b3ac and 4634272.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • composer.json
  • src/EventSubscriber/ApiExceptionSubscriber.php
  • src/Exception/DefaultExceptionToApiProblemTransformer.php
  • tests/Unit/EventSubscriber/ApiExceptionSubscriberTest.php
  • tests/Unit/Exception/DefaultExceptionToApiProblemTransformerTest.php

Walkthrough

This PR adds support for handling Symfony Messenger's HandlerFailedException by unwrapping it to process underlying exceptions, introduces handling for Symfony's security-layer AccessDeniedException with appropriate forbidden responses, and includes the symfony/security-core as a dev dependency.

Changes

Cohort / File(s) Summary
Dependencies
composer.json
Added symfony/security-core `^7.3
Exception Handling Logic
src/EventSubscriber/ApiExceptionSubscriber.php, src/Exception/DefaultExceptionToApiProblemTransformer.php
Enhanced exception processing: ApiExceptionSubscriber now unwraps HandlerFailedException before transformation; DefaultExceptionToApiProblemTransformer added mapping for security-layer AccessDeniedException to 403 Forbidden response.
Unit Tests
tests/Unit/EventSubscriber/ApiExceptionSubscriberTest.php, tests/Unit/Exception/DefaultExceptionToApiProblemTransformerTest.php
Added test case for HandlerFailedException unwrapping behavior and test dataset for AccessDeniedException mapping.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Messenger as Messenger Bus
    participant Subscriber as ApiExceptionSubscriber
    participant Transformer as DefaultExceptionToApiProblemTransformer
    participant Response

    Client->>Messenger: Handler execution
    Messenger->>Messenger: Handler throws exception
    Messenger->>Subscriber: Wraps in HandlerFailedException
    Subscriber->>Subscriber: Detect HandlerFailedException
    Subscriber->>Subscriber: Unwrap to underlying exception
    Subscriber->>Transformer: Pass unwrapped exception
    alt Is AccessDeniedException?
        Transformer->>Transformer: Map to forbidden()
    else Is ApiProblemException?
        Transformer->>Transformer: Transform accordingly
    else Other
        Transformer->>Transformer: Generic error handling
    end
    Transformer->>Response: Generate ApiProblem response
    Response->>Client: Return HTTP response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A handler wrapped in messenger's care,
Now unwrapped with security aware—
Exceptions flow from depths below,
To ApiProblems, formatted just so!
With tests in place, our code stands tall,

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the two main changes: unwrapping HandlerFailedException in the event subscriber and adding AccessDeniedException handling to the exception transformer.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch handler-exceptions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@stixx stixx added the bug Something isn't working label Apr 11, 2026
@stixx stixx merged commit 457c0dd into main Apr 11, 2026
3 checks passed
@stixx stixx deleted the handler-exceptions branch April 11, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant