error-handling - 如何在 Apigility 中使用 validation_messages 和 display_exceptions?

标签 error-handling exception-handling zend-framework2 laminas-api-tools

来自 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 via trace and exception_stack properties.

我不明白文档的这一部分。什么是目的 使用方法设置validation_messagesdisplay_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/

相关文章:

session - ZF2获取全局 session 容器

c# - Nido的ASP.NET C#异常处理

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

http - 发送带有 body 的 HEAD http 请求导致 net/http 错误

c++ - 未经授权的私有(private)类成员访问会产生编译时错误而不是运行时错误?

Java最终在方法级别阻塞并抛出异常

c++ - 覆盖默认的未处理异常行为

zend-framework2 - ZF2 中的 Controller 覆盖