/** * Render an exception into an HTTP response. * 该方法响应异常信息到客户端 : 该方法返回的数据必须是一个response对象 * 异常的处理是在请求结束前处理,因此这里的render 方法直接设定为返回异常信息给响应。 * @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); } $msg = $e->getmessage(); if ($e instanceof InvalidArgumentException) { return response()->json(['data' => $msg, 'state' => '901', 'timeStamp' => time()]); } if ($e instanceof UnexpectedValueException) { return response()->json(['data' => $msg, 'state' => '902', 'timeStamp' => time()]); } if ($e instanceof SignatureInvalidException) { return response()->json(['data' => $msg, 'state' => '903', 'timeStamp' => time()]); // return response()->view('welcome', [], 503); // return response("ddddd")->header("x-at",'xxx'); } if ($e instanceof BeforeValidException) { return response()->json(['data' => $msg, 'state' => '904', 'timeStamp' => time()]); } if ($e instanceof ExpiredException) { return response()->json(['data' => $msg, 'state' => '905', 'timeStamp' => time()]); } if ($e instanceof CustomException) { return response()->json(['data' => $msg, 'state' => '1005', 'timeStamp' => time()]); } return parent::render($request, $e); }
/** * 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); }
/** * 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); }
/** * 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); } else { if ($request->wantsJson()) { // Define the response $response = ['errors' => 'Sorry, something went wrong.', 'message' => $e->getMessage()]; // If the app is in debug mode if (config('app.debug')) { // Add the exception class name, message and stack trace to response $response['exception'] = get_class($e); // Reflection might be better here $response['trace'] = $e->getTrace(); } // Default response of 400 $status = 400; // If this exception is an instance of HttpException if ($this->isHttpException($e)) { // Grab the HTTP status code from the Exception $status = $e->getStatusCode(); } \Log::error($e); // Return a JSON response with the response array and status code return response()->json($response, $status); } } return parent::render($request, $e); }
/** * 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); }
/** * 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) { $status = 500; if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); $status = 404; } return response()->json(["error" => $e->getMessage()], $status); // return parent::render($request, $e); }
/** * 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 HttpException && \App::isLocal() === false) { Response::json(['result' => false, 'message' => $e->getMessage()])->setStatusCode($e->getStatusCode())->send(); exit; } return parent::render($request, $e); }
/** * 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 OAuthException) { $response = response()->json(['error' => $e->errorType, 'error_description' => $e->getMessage()], $e->httpStatusCode, $e->getHttpHeaders()); return $this->corsService->addActualRequestHeaders($response, $request); } return parent::render($request, $e); }
/** * 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); } // don't display SOAP Error if (str_contains($e->getMessage(), 'SOAP-ERROR')) { return; } return parent::render($request, $e); }
/** * 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); }
/** * 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()) { return Response::json(['code' => '', 'message' => $e->getMessage(), 'debugMessage' => $e->getTraceAsString()], 500); } else { return parent::render($request, $e); } }
/** * 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); } // add handler for Ajax requests if ($request->isXmlHttpRequest()) { return Response::json(['status' => '500', 'message' => $e->getMessage()], 500); } return parent::render($request, $e); }
/** * 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); } $message = !empty($e->getMessage()) ? $e->getMessage() : "Error"; // return view('errors.500')->with(compact('request', 'e', 'message')); return response()->view('errors.500', compact('request', 'e', 'message'), 500); // return response()->view('errors.500', compact('request', 'e'), 500); // return view('errors.500')->with(compact('request', 'e')); // return parent::render($request, $e); }
/** * 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 OAuthException) { return \ResponseFractal::setStatusCode($e->httpStatusCode)->respondCustomError($e->getMessage(), $e->errorType, [$e->parameter]); } if (config('app.debug')) { return $this->renderExceptionWithWhoops($e); } return parent::render($request, $e); }
/** * 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) { $user = $request->session()->get('user'); if ($e instanceof \PDOException) { return response()->view('pages.404', ['Missing', $e->getMessage(), 'user' => $user], 500); } if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } if ($e instanceof NotFoundHttpException) { return response()->view('pages.404', ['Missing', $e->getMessage(), 'user' => $user], 404); } return parent::render($request, $e); }
/** * 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 NotFoundHttpException) { return response()->view('errors.404', [], 404); } //As to preserve the catch all if ($e instanceof GeneralException) { return redirect()->back()->withInput()->withFlashDanger($e->getMessage()); } return parent::render($request, $e); }
/** * 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); }
/** * 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); } //As to preserve the catch all if ($e instanceof GeneralException) { return redirect()->back()->withInput()->withFlashDanger($e->getMessage()); } if ($e instanceof Backend\Access\User\UserNeedsRolesException) { return redirect()->route('admin.access.users.edit', $e->userID())->withInput()->withFlashDanger($e->validationErrors()); } //Catch all return parent::render($request, $e); }
/** * 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); } return parent::render($request, $e); /* COMMENT ABOVE AND UNCOMMENT BELOW TO REDIRECT FOR CUSTOM ERROR HANDLING */ /* if ($this->isHttpException($e)) { switch ($e->getStatusCode()) { // not found case 404: die("404 Redirect to Page not found here in app/Exceptions/Handler.php"); return redirect()->guest('home'); break; // internal error case '500': die("500 Redirect to internal error page here in app/Exceptions/Handler.php"); return redirect()->guest('home'); break; default: return $this->renderHttpException($e); break; } } else { return parent::render($request, $e); } */ }
/** * 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); } else { if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) { return response()->json(['errors' => ['The access token is expired.']], $e->getStatusCode()); } else { if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) { return response()->json(['errors' => ['The access token is invalid.']], $e->getStatusCode()); } else { if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) { return response()->json(['errors' => ['The internal server error is occured.']], $e->getStatusCode()); } else { if ($e instanceof NotFoundHttpException) { return response()->json(['errors' => ['The resource hasn\'t found.']], $e->getStatusCode()); } else { if ($e instanceof MethodNotAllowedHttpException) { return response()->json(['errors' => ['The method doesn\'t allowed for this resource.']], $e->getStatusCode()); } } } } } } return parent::render($request, $e); }
/** * 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) { // HTTP STATUS CODE 400 if ($e instanceof BadRequestHttpException) { if (\Request::ajax()) { return \Response::json(['status' => '400', 'message' => 'Bad Request']); } } // HTTP STATUS CODE 401 if ($e instanceof UnauthorizedHttpException) { if (\Request::ajax()) { return \Response::json(['status' => '401', 'message' => 'Unauthorized']); } } // HTTP STATUS CODE 403 if ($e instanceof AccessDeniedHttpException) { if (\Request::ajax()) { return \Response::json(['status' => '403', 'message' => 'Forbidden']); } } // HTTP STATUS CODE 404 if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException) { if (\Request::ajax()) { return \Response::json(['status' => '404', 'message' => 'Not Found']); } $e = new NotFoundHttpException($e->getMessage(), $e); } // else HTTP STATUS CODE 500 if (\Request::ajax()) { return \Response::json(['status' => '500', 'message' => 'Internal Server Error']); } return parent::render($request, $e); }
/** * 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) { /* * Notification on TokenMismatchException */ if ($e instanceof TokenMismatchException) { Notification::error(trans('global.Security token expired. Please, repeat your request.')); return redirect()->back()->withInput(); } if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } elseif ($e instanceof AuthorizationException) { $e = new HttpException(403, $e->getMessage()); } elseif ($e instanceof ValidationException && $e->getResponse()) { return $e->getResponse(); } if ($this->isHttpException($e)) { return $this->toIlluminateResponse($this->renderHttpException($e), $e); } else { // Custom error 500 view on production if (app()->environment() == 'production') { return response()->view('errors.500', [], 500); } return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e); } }
/** * 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 debug is enabled in local environment dump stack trace if (config('app.debug') and app()->environment('local')) { return class_exists('Whoops\\Run') ? $this->whoops($e) : parent::render($request, $e); } if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } // HTTP exceptions are are normally intentionally thrown and its safe to show their message if ($this->isHttpException($e)) { $code = $e->getStatusCode(); $message = $e->getMessage(); if (empty($message)) { $message = isset($this->httpCodes[$code]) ? $this->httpCodes[$code] : $this->httpCodes[500]; } } else { $code = $e->getCode(); if (!isset($this->httpCodes[$code])) { $code = 500; } $message = $this->httpCodes[$code]; } // If a custom view exist use it, otherwise use generic error page $view = view()->exists("errors/{$code}") ? "errors/{$code}" : 'layouts/error'; // Data for the view $data = ['title' => $message, 'code' => $code]; return response()->view($view, $data, $code); }
/** * HTTPレスポンスに対応する例外をレンダー * * @param \Illuminate\Http\Request $request * @param \Exception $e * * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if (config('app.debug')) { $whoops = new \Whoops\Run(); $whoops->pushHandler(new \Whoops\Hander\PrettyPageHander()); return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders()); } // CSRFトークンが存在しない、トークン不一致時に投げられる。 // TokenMismatchException例外を403で処理。 // もちろん適切であれば、HTTPステータスは自由に設定できる。 if ($e instanceof TokenMismatchException) { // abortヘルパーによりSymfony\Component\HttpFoundation\Exception\HttpException例外が // 投げられ、再度このrenderメソッドで処理される。この例外の // ステータスコードに一致するビューがapp/resources/views/errorsに // 存在していれば、そのビューが表示される。今回は403.blade.phpファイルが // 存在しているため、このファイルの内容がエラーページとして表示される。 abort(403); } // このrenderメソッドに最初から含まれている処理。 // EloquentのfindOrFailソッドなどが投げるModelNotFoundException例外を // 404エラーにしている。 if ($e instanceof ModelNotFoundException) { // 404エラー例外はabort(404)を使わず、次のように発生可能。 $e = new NotFoundHttpException($e->getMessage(), $e); } return parent::render($request, $e); }
/** * 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) { # Gazzete Errors if (Auth::check() && Auth::user()->hasRole(Role::SUBSCRIBER)) { if ($e instanceof NotFoundHttpException) { return redirect()->route('gazette.errors.404'); } if ($e instanceof TokenMismatchException) { return redirect()->route('gazette.errors.unauthorized'); } } # Management Errors if (Auth::check() && Auth::user()->hasRole(Role::ADMINISTRATOR)) { if ($e instanceof NotFoundHttpException) { return redirect()->route('management.errors.404'); } if ($e instanceof TokenMismatchException) { return redirect()->route('management.errors.unauthorized'); } if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } } return parent::render($request, $e); }
/** * 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 \UnknownPlayerException) { Bugsnag::notifyException($e); return response()->view('error', ['error' => $e->getMessage()]); } if ($e instanceof \DestinyException) { Bugsnag::notifyException($e); return response()->view('error', ['error' => $e->getMessage(), 'bungie' => true]); } if ($e instanceof \DestinyLegacyPlatformException) { return response()->view('error', ['error' => $e->getMessage(), 'bungie' => true]); } if (\Config::get('app.debug')) { \Session::flash('alert', sprintf("%s (Line %d): %s", $e->getFile(), $e->getLine(), $e->getMessage())); } else { if (strlen($e->getMessage()) > 1) { \Session::flash('alert', $e->getMessage()); } } if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } if (config('app.debug') && app()->environment() != 'testing') { return $this->renderExceptionWithWhoops($request, $e); } return parent::render($request, $e); }
/** * 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); } return parent::render($request, $e); }
/** * 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 (config('app.debug')) { return parent::render($request, $e); } if ($e instanceof TokenMismatchException) { return redirect()->back()->withInput($request->except('_token'))->withErrors('A sua sessão expirou. Tente novamente.'); } if (!$this->isHttpException($e)) { $pathInfo = $request->getPathInfo(); $url = $request->url(); $method = $request->method(); $message = $e->getMessage() ?: get_class($e); $data = ['pathInfo' => $pathInfo, 'url' => $url, 'method' => $method, 'exception' => $message, 'input' => $request->all()]; \Mail::send('emails.notify-webmaster', $data, function ($message) use($url) { $message->from('*****@*****.**'); $message->to('*****@*****.**', 'André Ascensão'); $message->subject("Exception at {$url}"); }); } return parent::render($request, $e); }
/** * 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); } return parent::render($request, $e);*/ $debug = env('APP_DEBUG'); if ($debug == 0) { if ($this->isHttpException($e)) { return $this->renderHttpException($e); } else { if ($e instanceof NotFoundHttpException) { return response()->view('errors.404', [], 400); } elseif ($e instanceof FatalErrorException) { return response()->view('errors.500', [], 500); } elseif ($e instanceof handleError) { return response()->view('errors.500', [], 500); } elseif ($e instanceof ModelNotFoundException) { return response()->view('errors.500', [], 500); } else { return response()->view('errors.500', [], 500); } } } else { if ($debug == 1) { //si es verdadero esta en modo debug y muestra el error if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } return parent::render($request, $e); } } }
/** * 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->acceptsJson() && $request->ajax()) { // Provide JSON response $response = ['success' => false, 'error' => '']; // Set response HTTP code and headers if ($e instanceof HttpExceptionInterface) { $code = $e->getStatusCode(); $headers = $e->getHeaders(); } else { $code = 500; $headers = []; } if ($e instanceof MaxUploadSizeException) { $response['error'] = 'File too big.'; } elseif ($e instanceof DisallowedFileTypeException) { $response['error'] = 'Disallowed file type.'; } else { $response['error'] = 'Server error.'; } // Add exception to response if debug mode is turned on if (config('app.debug') === true) { $response['exception'] = ['exception' => get_class($e), 'code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTrace(), 'file' => $e->getFile(), 'file_line' => $e->getLine()]; } return response()->json($response, $code, $headers); } else { // Normal HTML error page return parent::render($request, $e); } }