Пример #1
0
 /**
  * 重写异常处理方法
  *
  * @param \Exception $e
  * @return \Matrix\Http\json
  */
 public function onUncaughtException(\Exception $e)
 {
     //判断是否为参数验证错误
     if ($e instanceof ValidationException) {
         $errors = json_decode($e->getMessage(), true);
         return (new Response())->detail($errors);
     }
     //当前应用为 service 类型服务,直接输出错误信息
     if (self::$appType === 'service') {
         echo $e->getMessage();
         exit;
     }
     //当前应用为 api 类型服务,输出 api 格式返回信息
     if (self::$appType === 'api') {
         return (new Response())->apiDetail($e->getMessage());
     }
     //web H5 返回错误页面
     parent::onUncaughtException($e);
 }