[英]Unable to use ApiProblemListner in apigility using zf2
我是zendframework的新手。 我正在使用apigility进行休息服务,如果发生任何错误,则使用ApiProblemListner返回响应。
我在模型中有一个功能,此功能仅通过使用php异常的异常在catch块中使用
我在控制器中使用模型函数作为实用程序函数来捕获那些异常。 在捕获异常时我正在使用
try{
imageUploade(); // this function in model and throwing exception if any error
}catch(\Exception $e){
return new ApiProblemResponse(new ApiProblem(500 , $e->getMessage()));
}
如果imageUploade()如果图像大小更大,则抛出异常,那么我可以在catch块中捕获该异常。 我试过echo $e->getMessage();
如果我使用new ApiProblem(500 , $e->getMessage())
,它会打印异常bt new ApiProblem(500 , $e->getMessage())
它不会使用500消息重新调整json错误响应。 它什么也没返回。 即使没有显示任何错误。
似乎无法使用此类呈现错误。 我不确定是否需要添加任何事件。
我试图搜索文档,但找不到它。
提前致谢。
通常,如果您直接从控制器操作返回ApiProblemResponse
它应该可以工作。
您确定您的Api-Problem模块处于活动状态吗?
像这样尝试一次:
<?php
Application\Namespace;
use ZF\ApiProblem\ApiProblem;
use ZF\ApiProblem\ApiProblemResponse;
class IndexController
{
/**
* @return ApiProblemResponse
*/
public function indexAction()
{
return new ApiProblemResponse(new ApiProblem(500, 'test'));
}
}
如果那不起作用,那么我认为您的Api-Problem模块未运行或从未捕获到异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.