/** * 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) { \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); } 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 ($e instanceof HttpException) { // call i18n middleware manually since http exceptions won't be sent through it (new Internationalization())->handle($request, function () { }); } if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } if ($e instanceof MethodNotAllowedHttpException) { abort(403, 'Method not allowed.'); } if ($e instanceof PrettyPageException && PHP_SAPI != "cli") { return $e->showErrorPage(); } if ($e instanceof ValidationException) { // quick fix for returning 422 // @see https://prinzeugen.net/custom-responses-of-laravel-validations/ return $e->getResponse()->setStatusCode(200); } // render exceptions with whoops if (config('app.debug')) { foreach ($this->dontReport as $type) { if ($e instanceof $type) { return parent::render($request, $e); } } return $this->renderExceptionWithWhoops($e); } return response()->view('errors.brief', ['code' => 0, 'message' => 'cmn']); }
/** * 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); }
/** * 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 Cartalyst\Sentinel\Checkpoints\NotActivatedException) { // return response()->view('errors.custom', [], 500); return redirect('wait')->withErrors($e->getMessage()); } if ($e instanceof Cartalyst\Sentinel\Checkpoints\ThrottlingException) { $free = $e->getFree()->format('d M, h:i:s a'); switch ($e->getType()) { case 'global': $message = "Our site appears to be spammed. To give eveything a chance to calm down, please try again after {$free}."; break; case 'ip': $message = "Too many unauthorized attemps have been made against your IP address. Please wait until {$free} before trying again."; break; case 'user': $message = "Too many unauthorized attemps have been made against your account. For your security, your account is locked until {$free}."; break; } return redirect('auth/login')->withErrors($message); } 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);*/ $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->wantsJson()) { // Define the response $response = ['error' => 'Sorry, something went wrong: ']; // 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['message'] = $e->getMessage(); $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(); } // Return a JSON response with the response array and status code return response()->json($response, $status); } // Default to the parent class' implementation of handler 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); }
/** * 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) { 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) { // 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) { //return response()->view('404', [], 404); 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); } return parent::render($request, $e); //return response()->json(new WebResponseModel("fail", "Unknown error has occured. Please try again." , 0, 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); // return redirect()->back()->withErrors(['error' => 'Could not find a matching record!']); } 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) { if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } $response = parent::render($request, $e); $cors = app()->make('Asm89\\Stack\\CorsService'); return $cors->addActualRequestHeaders($response, $request); }
/** * 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 NotFoundHttpException) { return JsonResponse::create(["status" => "error", "message" => "the api is not found"]); } 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); // abort(404); } return parent::render($request, $e); // return redirect()->to('/'); }
/** * 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 (!config('app.debug')) { return response()->view('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 ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { return response(view('errors.not_found'), 404); } return parent::render($request, $e); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return Response */ public function render($request, Exception $e) { 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 ApiException) { return $this->customExceptionHandle($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 ($e instanceof TokenMismatchException) { return response()->json(['success' => false, 'error' => ['code' => Response::HTTP_FORBIDDEN, 'message' => 'Token mismatch']]); } 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 NotFoundHttpException) { return response()->view('error.404', ['message', $e->getMessage()], $e->getStatusCode()); } 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); } }