比如规定了POST方式请求接口,但是GET来请求会报如下图错误
那么如何自定义返回的错误呢?比如返回:{"error":"Method not allowed"}
1 回答
![?](http://img1.sycdn.imooc.com/5333a1bc00014e8302000200-100-100.jpg)
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
// 重写默认的notAllowedHandler
$container['notAllowedHandler'] = function ()
{
return function ($req, $res, $allowMethod) {
return $res->withJson([
"status" => 0,
"info" => "请求方法错误",
"data" => $allowMethod
]);
};
};
- 1 回答
- 0 关注
- 412 浏览
添加回答
举报
0/150
提交
取消