feat(dispatcher): 404 を Accept header で content-negotiation する (#312)#322
Merged
Conversation
FT7 F-1 で確認した「REST client が Accept: application/json を付けても
404.html を返す → ADR-0003 envelope の契約が 404 だけ守られていない」
問題を解消する。
- Dispatcher::notFoundResponse() に Accept ヘッダ判定を追加。JSON-preferring
client (application/json or application/* で q が text/html を上回る) には
ApiResponse->failure('NOT-FOUND') の JSON envelope を返す。HTML / browser
default (text/html, \*/\* 等) は従来どおり 404.html。
- NOT-FOUND code を config/error_codes.php に追加 (HTTP 404)。
- docs/development/error-codes.md / docs/api/openapi.yaml / docs/api/reference-client.md
に新 code とその branch 仕様を documentation。
- Unit test: Dispatcher::wantsJson() の content-negotiation を 5 ケース追加。
- HTTP smoke test: Accept 無し → HTML、Accept: application/json → JSON envelope
を 2 ケース追加。
Closes #312.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FT7 F-1 (Issue #312) の本体 fix。
何を直したか
`Dispatcher::notFoundResponse()` は常に `404.html` (`Content-Type: text/html`) を返していて、REST client が `Accept: application/json` を付けても HTML が返る → ADR-0003 envelope の契約が 404 だけ守られていなかった。
新たに `Dispatcher::wantsJson(string $acceptHeader): bool` を導入し、JSON-preferring client (`application/json` または `application/*` で q-value が `text/html` を上回る) には新 error code `NOT-FOUND` の JSON envelope を返す。HTML caller (`text/html`, 空 header, ワイルドカードのみ等) は従来どおり `404.html`。
仕様
Test plan
Doc updates
Closes #312.