Laravel框架中如何自定义API全局异常处理方法来优化长尾词搜索?
- 内容介绍
- 文章标签
- 相关推荐
本文共计235个文字,预计阅读时间需要1分钟。
python简化后的代码def find_user_by_id(id): result=User::find(id) if result.empty(): raise ApiException('获取失败') else: return json_decode(result)
api返回实现
$result = User::find($id); if(empty($result)){ throw new ApiException('获取失败'); } else{ return json_decode($result); }
api返回信息
{ "msg": "", "data": "获取失败", "status": 0 }
1,添加异常类
namespace App\Exceptions; class ApiException extends \Exception { function _construct($msg='') { parent::_construct($msg); } }
2,修改laravel异常类u。。。
本文共计235个文字,预计阅读时间需要1分钟。
python简化后的代码def find_user_by_id(id): result=User::find(id) if result.empty(): raise ApiException('获取失败') else: return json_decode(result)
api返回实现
$result = User::find($id); if(empty($result)){ throw new ApiException('获取失败'); } else{ return json_decode($result); }
api返回信息
{ "msg": "", "data": "获取失败", "status": 0 }
1,添加异常类
namespace App\Exceptions; class ApiException extends \Exception { function _construct($msg='') { parent::_construct($msg); } }
2,修改laravel异常类u。。。

