gpt4 book ai didi

php - FOSRestBundle:显示我的自定义异常消息

转载 作者:行者123 更新时间:2023-12-01 09:25:41 26 4
gpt4 key购买 nike

我正在尝试在 FOSRestBundle 中添加自定义异常控件,但它似乎忽略了我的自定义消息(响应的状态代码正常)。

我有:

throw new HttpException(404, "User {$id} not found");

但是得到这个json响应:
{
"error": {
"code": 404,
"message": "Not Found"
}
}

所以我找不到显示我的自定义消息的方法

最佳答案

您还可以使用以下配置抛出自己的异常:

fos_rest:
exception:
codes:
'My\Custom\NotFound\Exception404': 404
messages:
'My\Custom\NotFound\Exception404': true

在您自己的异常类中提供自定义消息,它应该按预期工作。

关于php - FOSRestBundle:显示我的自定义异常消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24979499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com