JSON:API: 404/405 router errors are empty, and error objects have a non-spec `type` member
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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).
-
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 nostatus,titleordetail:{"errors":[{"id":"/.well-known/genid/1d2136a82a8b3a05d6a2"}]} -
Error objects have a
typemember. 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\ErrorNormalizercopies the problemtypetolinks.type, which is correct, but it also keeps it as atypemember:{"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,codeandlinks.type. - Error objects have no
typemember. The value stays inlinks.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.
- 主要语言
- PHP
- 星标
- 2.6k
- 派生
- 989
- 平均合并
- 2 天 2 小时
- 30 天内合并 PR
- 101
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
api-platform/core 的其他 Issue
-
难度 2/5 1 小时以内 新手友好度 80/100
api-platform/core#8701 ·
维护者通常 1 天内回复
-
JSON:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`未关闭
难度 2/5 1-3 小时 新手友好度 82/100
api-platform/core#8699 ·
维护者通常 1 天内回复
-
api:openapi:export --spec-version=3.0.0 outputs `webhooks`, which is invalid in OpenAPI 3.0可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
api-platform/core#8690 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
api-platform/core#8680 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
api-platform/core#8703 ·
维护者通常 1 天内回复
查看 api-platform/core 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
Featured image not passed to checks in the Tasks column or publish blocks可能已有人在做 @roborourke 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
humanmade/publication-checklist#100 ·
维护者通常 1 天内回复
-
bug customer-reported
难度 2/5 1-3 小时 新手友好度 62/100
MagnaCapax/PMSS#1072 ·
维护者通常 5 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
hestiacp/hestiacp#5800 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 68/100
components-web-app/docs#244 ·