1313
1414namespace ApiPlatform \Laravel \ApiResource ;
1515
16- use ApiPlatform \JsonLd \ ContextBuilderInterface ;
16+ use ApiPlatform \JsonSchema \ SchemaFactory ;
1717use ApiPlatform \Metadata \ApiProperty ;
1818use ApiPlatform \Metadata \Error as Operation ;
1919use ApiPlatform \Metadata \ErrorResource ;
20+ use ApiPlatform \Metadata \ErrorResourceInterface ;
2021use ApiPlatform \Metadata \Exception \HttpExceptionInterface ;
2122use ApiPlatform \Metadata \Exception \ProblemExceptionInterface ;
23+ use ApiPlatform \State \ErrorProvider ;
2224use Symfony \Component \HttpKernel \Exception \HttpExceptionInterface as SymfonyHttpExceptionInterface ;
2325use Symfony \Component \Serializer \Annotation \Groups ;
2426use Symfony \Component \Serializer \Annotation \Ignore ;
2527use Symfony \Component \Serializer \Annotation \SerializedName ;
2628use Symfony \Component \WebLink \Link ;
2729
2830#[ErrorResource(
29- types: [ ' hydra:Error ' ] ,
31+ uriTemplate: ' /errors/{status}{._format} ' ,
3032 openapi: false ,
3133 uriVariables: ['status ' ],
3234 operations: [
3335 new Operation (
36+ errors: [],
3437 name: '_api_errors_problem ' ,
35- outputFormats: ['json ' => ['application/problem+json ' ]],
38+ routeName: '_api_errors ' ,
39+ outputFormats: ['json ' => ['application/problem+json ' , 'application/json ' ]],
40+ hideHydraOperation: true ,
3641 normalizationContext: [
42+ SchemaFactory::OPENAPI_DEFINITION_NAME => '' ,
3743 'groups ' => ['jsonproblem ' ],
3844 'skip_null_values ' => true ,
45+ 'ignored_attributes ' => ['trace ' , 'file ' , 'line ' , 'code ' , 'message ' , 'traceAsString ' , 'previous ' ],
3946 ],
40- uriTemplate: '/errors/{status} '
4147 ),
4248 new Operation (
49+ errors: [],
4350 name: '_api_errors_hydra ' ,
44- outputFormats: ['jsonld ' => ['application/problem+json ' ]],
51+ routeName: '_api_errors ' ,
52+ outputFormats: ['jsonld ' => ['application/problem+json ' , 'application/ld+json ' ]],
4553 normalizationContext: [
54+ SchemaFactory::OPENAPI_DEFINITION_NAME => '' ,
4655 'groups ' => ['jsonld ' ],
4756 'skip_null_values ' => true ,
57+ 'ignored_attributes ' => ['trace ' , 'file ' , 'line ' , 'code ' , 'message ' , 'traceAsString ' , 'previous ' ],
4858 ],
49- links: [new Link (rel: ContextBuilderInterface::JSONLD_NS .'error ' , href: 'http://www.w3.org/ns/hydra/error ' )],
50- uriTemplate: '/errors/{status}.jsonld '
59+ links: [new Link (rel: 'http://www.w3.org/ns/json-ld#error ' , href: 'http://www.w3.org/ns/hydra/error ' )],
5160 ),
5261 new Operation (
62+ errors: [],
5363 name: '_api_errors_jsonapi ' ,
64+ routeName: '_api_errors ' ,
65+ hideHydraOperation: true ,
5466 outputFormats: ['jsonapi ' => ['application/vnd.api+json ' ]],
55- normalizationContext: ['groups ' => ['jsonapi ' ], 'skip_null_values ' => true ],
56- uriTemplate: '/errors/{status}.jsonapi '
67+ normalizationContext: [
68+ SchemaFactory::OPENAPI_DEFINITION_NAME => '' ,
69+ 'disable_json_schema_serializer_groups ' => false ,
70+ 'groups ' => ['jsonapi ' ],
71+ 'skip_null_values ' => true ,
72+ 'ignored_attributes ' => ['trace ' , 'file ' , 'line ' , 'code ' , 'message ' , 'traceAsString ' , 'previous ' ],
73+ ],
74+ ),
75+ new Operation (
76+ name: '_api_errors ' ,
77+ hideHydraOperation: true ,
78+ extraProperties: ['_api_disable_swagger_provider ' => true ],
79+ outputFormats: ['html ' => ['text/html ' ], 'jsonapi ' => ['application/vnd.api+json ' ], 'jsonld ' => ['application/ld+json ' ], 'json ' => ['application/problem+json ' , 'application/json ' ]],
5780 ),
5881 ],
59- graphQlOperations: []
82+ outputFormats: ['jsonapi ' => ['application/vnd.api+json ' ], 'jsonld ' => ['application/ld+json ' ], 'json ' => ['application/problem+json ' , 'application/json ' ]],
83+ provider: ErrorProvider::class,
84+ graphQlOperations: [],
85+ description: 'A representation of common errors. ' ,
6086)]
61- class Error extends \Exception implements ProblemExceptionInterface, HttpExceptionInterface
87+ #[ApiProperty(property: 'previous ' , hydra: false , readable: false )]
88+ #[ApiProperty(property: 'traceAsString ' , hydra: false , readable: false )]
89+ #[ApiProperty(property: 'string ' , hydra: false , readable: false )]
90+ class Error extends \Exception implements ProblemExceptionInterface, HttpExceptionInterface, ErrorResourceInterface
6291{
6392 /**
6493 * @var array<int, mixed>
@@ -73,7 +102,7 @@ public function __construct(
73102 private readonly string $ title ,
74103 private readonly string $ detail ,
75104 #[ApiProperty(identifier: true )] private int $ status ,
76- array $ originalTrace ,
105+ array $ originalTrace = [] ,
77106 private readonly ?string $ instance = null ,
78107 private string $ type = 'about:blank ' ,
79108 private array $ headers = [],
0 commit comments