首先在建立公共文件
application\common\lib\exception\ApiHandleException.php
<?php /** * Created by PhpStorm. * User: leiliang * Date: 2018/4/24 * Time: 21:56 */ namespace app\common\lib\exception; use Exception; use think\exception\Handle; class ApiHandleException extends Handle{ /** * http 状态码 * @var int */ public $httpCode = 500; public function render(Exception $e) { return json([ 'status' => 0, 'message' => $e->getMessage(), 'data' =>[], ],$this->httpCode); } }
修改application\config.php
'exception_handle' => '\app\common\lib\exception\ApiHandleException',
这样报错信息就可以以接口的形式输出
{ "status": 0, "message": "Undefined variable: data", "data": [] }
简简单单:666
2018-06-06 13:19:22 回复