示例#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)
 {
     \App\Http\Controllers\BaseController::setHeader();
     /**
      * Handle Service Exceptions
      */
     if ($e instanceof \App\Exceptions\ServiceException) {
         $response = array('status' => $e->getCode(), 'message' => $e->getMessage());
         ServiceLog::requestLog($request, $response);
         return \Response::json($response);
     }
     if (!\Config::get('app.debug')) {
         if ($e instanceof ModelNotFoundException) {
             $e = new NotFoundHttpException($e->getMessage(), $e);
         }
         if ($e instanceof \Illuminate\Contracts\Container\BindingResolutionException) {
             $response = array('status' => 604, 'message' => '相应服务没有启动');
         } elseif ($e instanceof \Symfony\Component\Debug\Exception\FatalErrorException) {
             $response = array('status' => 605, 'message' => 'method wrong');
         } else {
             $response = array('status' => $e->getCode() ?: 606, 'message' => $e->getMessage() ?: '请检查请求数据');
         }
         ServiceLog::errorLog($request, $response);
         return \Response::json($response);
     }
     return parent::render($request, $e);
 }
示例#2
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)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     /**
      * Response Exception as Json
      *
      */
     if ($request->wantsJson()) {
         $error = new \stdclass();
         $error->error = true;
         if ($e instanceof NotFoundHttpException) {
             $error->code = $e->getStatusCode();
         } else {
             $error->code = $e->getCode();
         }
         if ($error->code == 0) {
             $error->code = 400;
         }
         if ($e instanceof ValidatorException) {
             $error->message = $e->getMessageBag();
         } else {
             $error->message = $e->getMessage();
             if (\App::environment('local')) {
                 $error->file = $e->getFile();
                 $error->line = $e->getLine();
             }
         }
         return response()->json($error, $error->code);
     }
     return parent::render($request, $e);
 }
示例#3
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)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof ApiException) {
         return response()->json(['error' => true, 'message_info' => $e->getMessage()], $e->getCode());
     }
     return parent::render($request, $e);
 }
示例#4
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)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if ($request->ajax() || $request->wantsJson()) {
         $json = ['success' => false, 'error' => ['code' => $e->getCode(), 'message' => $e->getMessage()]];
         return response()->json($json, 400);
     }
     return parent::render($request, $e);
 }
示例#5
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)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     if ($e instanceof HttpException) {
         $errorData = ["message" => $e->getMessage(), "httpCode" => $e->getStatusCode(), "code" => $e->getCode()];
         if ($request->ajax()) {
             return response()->json($errorData, $errorData['httpCode']);
         } else {
             return response()->view('errors.phylab', $errorData, $errorData['httpCode']);
         }
     }
     return parent::render($request, $e);
 }