14
14
namespace ApiPlatform \Hydra \Serializer ;
15
15
16
16
use ApiPlatform \Api \UrlGeneratorInterface as LegacyUrlGeneratorInterface ;
17
+ use ApiPlatform \JsonLd \Serializer \HydraPrefixTrait ;
17
18
use ApiPlatform \Metadata \UrlGeneratorInterface ;
18
19
use ApiPlatform \Serializer \CacheableSupportsMethodInterface ;
19
20
use ApiPlatform \State \ApiResource \Error ;
32
33
final class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
33
34
{
34
35
use ErrorNormalizerTrait;
36
+ use HydraPrefixTrait;
35
37
36
38
public const FORMAT = 'jsonld ' ;
37
39
public const TITLE = 'title ' ;
@@ -47,11 +49,12 @@ public function __construct(private readonly LegacyUrlGeneratorInterface|UrlGene
47
49
*/
48
50
public function normalize (mixed $ object , ?string $ format = null , array $ context = []): array |string |int |float |bool |\ArrayObject |null
49
51
{
52
+ $ hydraPrefix = $ this ->getHydraPrefix ($ context );
50
53
$ data = [
51
54
'@context ' => $ this ->urlGenerator ->generate ('api_jsonld_context ' , ['shortName ' => 'Error ' ]),
52
- '@type ' => ' hydra: Error ' ,
53
- ' hydra: title ' => $ context [self ::TITLE ] ?? $ this ->defaultContext [self ::TITLE ],
54
- ' hydra: description ' => $ this ->getErrorMessage ($ object , $ context , $ this ->debug ),
55
+ '@type ' => $ hydraPrefix . ' Error ' ,
56
+ $ hydraPrefix . ' title ' => $ context [self ::TITLE ] ?? $ this ->defaultContext [self ::TITLE ],
57
+ $ hydraPrefix . ' description ' => $ this ->getErrorMessage ($ object , $ context , $ this ->debug ),
55
58
];
56
59
57
60
if ($ this ->debug && null !== $ trace = $ object ->getTrace ()) {
0 commit comments