来自 Apigility 文档(Error Reporting):
The API Problem specification allows you to compose any other additional fields that you feel would help further clarify the problem and why it occurred. Apigility uses this fact to provide more information in several ways:
- Validation error messages are reported via a
validation_messages
key.- When the
display_exceptions
view configuration setting is enabled, stack traces are included viatrace
andexception_stack
properties.
我不明白文档的这一部分。什么是目的 和 使用方法设置
validation_messages
和 display_exceptions
?
最佳答案
display_exceptions
设置来自 ZF2 的 View 管理器 (see docs here)。开启此功能将导致 Apigiltiy 包含带有任何错误响应的堆栈跟踪。
在 Apigility 本身中,validation_messages
自动处理关键人口。您配置一个输入过滤器来验证传入的数据负载,如果输入过滤器失败,它返回的错误消息会自动注入(inject)到 validation_messages
下的 API 响应中。 key 。此功能由模块 zf-content-validation
提供.您可以通过返回 ApiProblemResponse
来“自己做”从您的资源中,如下所示:
return new ApiProblemResponse(
new ApiProblem(422, 'Failed Validation', null, null, array(
'validation_messages' => [ /* array of messages */ ]
))
);
关于error-handling - 如何在 Apigility 中使用 validation_messages 和 display_exceptions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29939300/