首页 > 解决方案 > Symfony 2 - 在生产中不返回 POST Json 自定义消息异常

问题描述

我正在使用 Symfony 2.8

我有一个 POST 方法根。返回格式为json。

app_patient_create:
path: /
methods: [POST]
defaults:
    _controller: App:Patient:create
    _format: json
    _angular_safe: true

在这个根目录的监听器中,我有一个例外。

throw new Exception\MaxPointsException();

这是自定义异常:

namespace App\Training\Exception;

class MaxPointsException extends \LogicException
{
    public function __construct()
    {
        parent::__construct('Vous avez atteint le nombre maximal de patients inclus dans votre offre découverte. Pour continuer à profiter du site, veuillez vous abonner');
    }
}

在开发环境中,消息是 return :

在此处输入图像描述

但不在产品环境中:

在此处输入图像描述

你知道为什么吗?

标签: symfonyexceptionsymfony-2.8custom-exceptions

解决方案


我使用 HTTP 409 响应来识别我的异常。


推荐阅读