symfony2中fosrest bundle的自定义异常
嗨,我正在尝试添加自定义异常,但它不起作用 现在我的回答是:(同样,故障调试程序不是该类的触发器) 这是fos rest的默认例外情况 我添加了一个新类来包装异常symfony2中fosrest bundle的自定义异常,symfony,fosrestbundle,Symfony,Fosrestbundle,嗨,我正在尝试添加自定义异常,但它不起作用 现在我的回答是:(同样,故障调试程序不是该类的触发器) 这是fos rest的默认例外情况 我添加了一个新类来包装异常 class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface { public function wrap($data) { $exception = $data['exception']; $newException = array
class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface {
public function wrap($data)
{
$exception = $data['exception'];
$newException = array(
'success' => false,
'exception' => array(
'exceptionClass' => $exception->getClass(),
'message' => $data['status_text']
)
);
return $newException;
}
}
我的配置文件:
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
routing_loader:
default_format: json
view:
view_response_listener: force
formats:
json: true
xml: true
templating_formats:
html: false
# exception_wrapper_handler: CLASS path
exception:
enabled: true
service:
exception_handler: appname.exception_handler
serializer: jms_serializer.serializer
serializer:
serialize_null: true
您需要将Exception类添加到config.yml中fos_rest配置中的Exception.messages数组中,以便它显示自定义消息
fos_rest:
exception:
enabled: true
messages:
'AppBundle\ExpeptionHandler\ ExceptionWrapperHandler': true
您需要将Exception类添加到config.yml中fos_rest配置中的Exception.messages数组中,以便它显示自定义消息
fos_rest:
exception:
enabled: true
messages:
'AppBundle\ExpeptionHandler\ ExceptionWrapperHandler': true