示例#1
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     $isDebug = !!config("app.debug");
     //是否是debug的状态
     $isAjax = $request->ajax();
     $process = array();
     //异常的处理方法
     $process[DeepInException::class] = function () use($isAjax, $isDebug, $e) {
         if ($isAjax) {
             return Client::errorJSON($e->getCode(), $e->getMessage(), array());
         } else {
             return \Response::make(Client::error($e->getMessage(), null, array()));
         }
     };
     $process[QueryException::class] = function () use($isAjax, $isDebug, $e) {
         if ($isAjax) {
             return Client::errorJSON($e->getCode(), "数据操作错误", array());
         } else {
             return \Response::make(Client::error("数据操作错误" . $e->getMessage(), null, array()));
         }
     };
     //sql异常
     $process[DeepInHtmlException::class] = $process[DeepInException::class];
     //html异常
     //登陆异常
     $process[LoginException::class] = function () use($isAjax, $isDebug, $e) {
         return \Response::make($e->getMessage());
     };
     //未登陆异常
     $process[UnLoginException::class] = function () use($isAjax, $isDebug, $e) {
         $data = array();
         if ($e instanceof UnLoginException) {
             $data = $e->getData();
         }
         if (isset($data['url'])) {
             $data['url'] = "/auth";
         }
         $url = $data['url'];
         if ($isAjax == false) {
             return redirect($url);
         }
         return Client::errorJSON($e->getCode(), $e->getMessage(), $data);
     };
     $className = get_class($e);
     if (isset($process[$className])) {
         return $process[$className]();
     }
     return parent::render($request, $e);
 }
 /**
  * 操作成功
  * @param $msg
  * @param null $url
  * @param array $data
  * @param int $delay
  * @return \Illuminate\View\View
  */
 public function success($msg, $url = null, $data = array(), $delay = 3)
 {
     return Client::success($msg, $url, $data, $delay);
 }