<?php namespace app\common\exception; use Exception; use think\exception\Handle; use think\exception\HttpException; use think\exception\ValidateException; class Http extends Handle { public function render(Exception $e) { $json = [ 'code' => 1, 'message' => '', 'data' => [] ]; // 参数验证错误 if ($e instanceof ValidateException) { $json['message'] = $e->getError(); return json($json); } // 请求异常 if ($e instanceof HttpException && request()->isAjax()) { $json['message'] = $e->getMessage(); return json($json,$e->getStatusCode()); } $json['message'] = $e->getMessage(); return json($json); } }