Skip to content

Conversation

@daFish
Copy link
Contributor

@daFish daFish commented Nov 30, 2025

Fixes undefined array key warning when normalizing exceptions that don't have attributes in their normalized structure.

This typically occurs with ItemNotFoundException when invalid resource identifiers are provided.

Q A
Branch? 4.2
Tickets not applicable
License MIT
Doc PR not applicable

Description

Fixes an undefined array key warning in ErrorNormalizer when normalizing exceptions that don't have an attributes key in their normalized structure.

Problem

When ItemNotFoundException or similar exceptions are thrown for invalid resource identifiers, the ErrorNormalizer::normalize() method assumes that $jsonApiObject['data']['attributes'] exists, causing a warning.

Solution

Added defensive checks to handle cases where the attributes key is not present, providing a fallback error structure that conforms to the JSON:API specification.

@daFish daFish force-pushed the fix/jsonapi-error-normalizer-missing-attributes branch 2 times, most recently from 87e290e to 918e2fd Compare November 30, 2025 20:15
@daFish daFish changed the base branch from main to 4.2 November 30, 2025 20:21
@daFish daFish force-pushed the fix/jsonapi-error-normalizer-missing-attributes branch 2 times, most recently from 76cf3de to 0a5c97c Compare December 18, 2025 18:53
Fixes undefined array key warning when normalizing exceptions
that don't have attributes in their normalized structure.

This typically occurs with ItemNotFoundException when invalid
resource identifiers are provided.
@daFish daFish force-pushed the fix/jsonapi-error-normalizer-missing-attributes branch from 0a5c97c to 5938c2b Compare December 19, 2025 06:18
@daFish
Copy link
Contributor Author

daFish commented Dec 19, 2025

@soyuka The unit test has been removed and I have added a Behat test.

@soyuka soyuka force-pushed the fix/jsonapi-error-normalizer-missing-attributes branch from fbc7ec2 to 1afec8c Compare December 19, 2025 14:03
@soyuka soyuka force-pushed the fix/jsonapi-error-normalizer-missing-attributes branch from 1afec8c to d6ea749 Compare December 19, 2025 14:13
@soyuka soyuka merged commit d847ad6 into api-platform:4.2 Dec 19, 2025
2 checks passed
@daFish daFish deleted the fix/jsonapi-error-normalizer-missing-attributes branch December 19, 2025 14:40
aaa2000 added a commit to aaa2000/core that referenced this pull request Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants