@@ -35,7 +35,17 @@ public function __construct(private ?NormalizerInterface $itemNormalizer = null,
3535 public function normalize (mixed $ data , ?string $ format = null , array $ context = []): array
3636 {
3737 if ($ data instanceof FlattenException) {
38- $ error = $ this ->flattenExceptionToError ($ data , $ format , $ context );
38+ $ type = \sprintf ('/errors/%d ' , $ data ->getStatusCode ());
39+ unset($ context ['exception ' ]);
40+ $ problem = $ this ->problemNormalizer ->normalize ($ data , $ format , ['type ' => $ type ] + $ context );
41+ $ error = [
42+ 'id ' => $ problem ['type ' ],
43+ 'title ' => $ problem ['title ' ],
44+ 'detail ' => $ problem ['detail ' ],
45+ 'status ' => $ problem ['status ' ],
46+ 'type ' => $ problem ['type ' ],
47+ 'code ' => (string ) $ problem ['status ' ],
48+ ];
3949 } else {
4050 $ jsonApiObject = $ this ->itemNormalizer ->normalize ($ data , $ format , $ context );
4151 $ error = $ jsonApiObject ['data ' ]['attributes ' ] ?? [];
@@ -77,22 +87,6 @@ public function normalize(mixed $data, ?string $format = null, array $context =
7787 return ['errors ' => $ errors ];
7888 }
7989
80- private function flattenExceptionToError (FlattenException $ exception , ?string $ format , array $ context ): array
81- {
82- $ type = \sprintf ('/errors/%d ' , $ exception ->getStatusCode ());
83- unset($ context ['exception ' ]);
84- $ problem = $ this ->problemNormalizer ->normalize ($ exception , $ format , ['type ' => $ type ] + $ context );
85-
86- return [
87- 'id ' => $ problem ['type ' ],
88- 'title ' => $ problem ['title ' ],
89- 'detail ' => $ problem ['detail ' ],
90- 'status ' => $ problem ['status ' ],
91- 'type ' => $ problem ['type ' ],
92- 'code ' => (string ) $ problem ['status ' ],
93- ];
94- }
95-
9690 /**
9791 * {@inheritdoc}
9892 */
0 commit comments