Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

JSON:API: 404/405 router errors are empty, and error objects have a non-spec `type` member

Ouverte
#8,704 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
50/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
php, symfony
Domaine
api

Piste de recherche

Start with JsonApi\Serializer\ErrorNormalizer in src/JsonApi/Serializer and reproduce with the Novel resource from the issue. Compare the bodies of GET /nope, DELETE /novels/1 and GET /novels/999 to find where the non-operation errors lose their status, title and detail. Done when the 404 and 405 errors carry the same members as the operation errors, and no error object has a type member while links.type remains.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

API Platform version(s) affected

4.4.4

Description

The JSON:API error documents have two problems that remain after #8366 (which makes status a string on main).

  1. Errors that do not come from an operation are empty. An unknown route (404) or a method that is not allowed (405) answers with an error object that has only a generated id. It has no status, title or detail:

    {"errors":[{"id":"/.well-known/genid/1d2136a82a8b3a05d6a2"}]}
    
  2. Error objects have a type member. The spec lists the members of an error object (id, links, status, code, title, detail, source, meta), and "Unless otherwise noted, objects defined by this specification or any applied extensions MUST NOT contain any additional members." JsonApi\Serializer\ErrorNormalizer copies the problem type to links.type, which is correct, but it also keeps it as a type member:

    {"errors":[{"id":"/errors/404","title":"An error occurred","detail":"Not Found","status":404,"type":"/errors/404","links":{"type":"/errors/404"},"code":"404"}]}
    

#3042 is about the older problem+json format. These two problems are in the current errors format.

How to reproduce
#[ApiResource(operations: [
    new Get(provider: [self::class, 'provide']),
    new Post(processor: [self::class, 'process']),
])]
final class Novel
{
    public int $id = 1;
    public string $title = 'Dune';

    public static function provide(): ?self { return null; }
    public static function process(self $data, Operation $operation): self { return $data; }
}
Request Status Body
GET /nope 404 {"errors":[{"id":"/.well-known/genid/…"}]}
DELETE /novels/1 405 {"errors":[{"id":"/.well-known/genid/…"}]}
GET /novels/999 404 {"errors":[{"id":"/errors/404","title":"An error occurred","detail":"Not Found","status":404,"type":"/errors/404","links":{"type":"/errors/404"},"code":"404"}]}
POST /novels with {"data":{"type":"Novel","attributes":{"title":5}}} 400 {"errors":[{"id":"/errors/400","title":"An error occurred","detail":"The type of the \"title\" attribute must be \"string\", \"integer\" given.","status":400,"type":"/errors/400","links":{"type":"/errors/400"},"code":"400"}]}

Expected:

  • The 404 and 405 errors have the same members as the other errors: status, title, detail, code and links.type.
  • Error objects have no type member. The value stays in links.type.
Additional Context

Checked on api-platform/core v4.4.4, Symfony 7.4, PHP 8.5, in an empty Symfony app. The related code in src/JsonApi/Serializer is the same on main, except for the error status cast (#8366).

The app has only FrameworkBundle, TwigBundle and ApiPlatformBundle, with this config:

$c->extension('api_platform', [
    'mapping' => ['paths' => ['%kernel.project_dir%/src/ApiResource']],
    'formats' => ['jsonapi' => ['application/vnd.api+json']],
    'error_formats' => ['jsonapi' => ['application/vnd.api+json'], 'jsonproblem' => ['application/problem+json']],
    'doctrine' => ['enabled' => false],
]);

All requests send Accept: application/vnd.api+json and, when they have a body, Content-Type: application/vnd.api+json. The responses are from the prod environment.

Langage dominant
PHP
Étoiles
2.6k
Forks
989
Merge moyen
2 j 2 h
PR mergées (30 j)
101

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de api-platform/core

Toutes les issues de api-platform/core

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.