【发布时间】:2017-08-08 07:58:45
【问题描述】:
如何在返回的响应中显示验证错误和消息。 我只是像这样检索响应:
{
"message": "4 validation errors occurred",
"url": "/api/posts",
"code": 422
}
【问题讨论】:
标签: api validation debugging cakephp-3.0 crud
如何在返回的响应中显示验证错误和消息。 我只是像这样检索响应:
{
"message": "4 validation errors occurred",
"url": "/api/posts",
"code": 422
}
【问题讨论】:
标签: api validation debugging cakephp-3.0 crud
我找到了here:
异常处理程序需要配置:
-如果您的 CakePHP >= 3.3(中间件功能):
'Error' => [
'errorLevel' => E_ALL,
'exceptionRenderer' => 'Crud\Error\JsonApiExceptionRenderer',
'skipLog' => [],
'log' => true,
'trace' => true,
],
-如果你的 CakePHP
<?php
class AppController extends Controller {
public function initialize()
{
parent::initialize();
$this->Crud->config(['listeners.api.exceptionRenderer' => 'App\Error\ExceptionRenderer']);
}
}
【讨论】: