-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonSchemaExceptionHandlerInterface doesn't catch JsonException in requests #199
Comments
@sosuke-ito Sorry for the late response. |
@sosuke-ito ping |
AIの考察要点まとめ
BEAR.Resource 側の意図と現在の実装
このように「レスポンス検証だけはエラーハンドラで包むが、リクエスト検証はそうしない」構造になっている背景としては、
という使い分けが想定されるからです。 Issue として挙がっている提案
という形で、「もしこれが意図的でないなら、上記の差分パッチのようにリクエスト不正時にもハンドラーを呼べるようにしませんか?」という提案が挙がっています。 --- a/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php
+++ b/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php
@@ -63,11 +63,11 @@ final class JsonSchemaInterceptor implements MethodInterceptor
$method = $invocation->getMethod();
/** @var JsonSchema $jsonSchema */
$jsonSchema = $method->getAnnotation(JsonSchema::class);
- if ($jsonSchema->params) {
- $arguments = $this->getNamedArguments($invocation);
- $this->validateRequest($jsonSchema, $arguments);
- }
/** @var ResourceObject $ro */
+ $ro = $this->validateRequest($jsonSchema, $invocation);
+ if ($ro->code === 400) {
+ return $ro;
+ }
$ro = $invocation->proceed();
... このパッチでは、リクエストが不整合のとき メリット
デメリット
結論・コメント
もし「アプリケーション全体で統一的に
という流れが自然かと思います。 まとめとしては:
という回答になります。 |
JsonSchemaExceptionHandlerInterface
handlesJsonException
s on ill-formed responses but not on ill-formed requests.Is this behavior intentional?
Example
For example, in this test case
BEAR.Resource/tests/Module/JsonSchemaFakeModuleTest.php
Lines 42 to 53 in 6211582
we get
JsonException
when we provide$gender = 'invalid gender'
even if we bind a handler toJsonSchemaExceptionHandlerInterface
.I guess this is intentional, because ill-formed requests normally cannot continue and end up with abort. We might need handlers for this if we want to return some error-reason-responses or specify errors in response headers.
Proposal
If this is NOT intentional, we may want to handle
JsonException
s thrown in the request validation here:BEAR.Resource/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php
Lines 60 to 84 in d28d3ba
Although I've got no good idea. Like this? (maybe BC-break):
The text was updated successfully, but these errors were encountered: