本文整理汇总了PHP中Illuminate\Foundation\Exceptions\Handler::convertExceptionToResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Handler::convertExceptionToResponse方法的具体用法?PHP Handler::convertExceptionToResponse怎么用?PHP Handler::convertExceptionToResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Foundation\Exceptions\Handler
的用法示例。
在下文中一共展示了Handler::convertExceptionToResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertExceptionToResponse
/**
* Create a Symfony response for the given exception.
*
* @param \Exception $e
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @SuppressWarnings(PHPMD.ShortVariable)
*/
protected function convertExceptionToResponse(Exception $e)
{
if (config('app.debug')) {
return $this->renderExceptionWithWhoops($e);
}
return parent::convertExceptionToResponse($e);
}
示例2: convertExceptionToResponse
/**
* @param \Exception $e
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function convertExceptionToResponse(Exception $e) : Response
{
if (!request()->ajax() && !request()->wantsJson()) {
return parent::convertExceptionToResponse($e);
}
return response()->json(["code" => 500, "message" => $e->getMessage()], 500);
}
示例3: convertExceptionToResponse
protected function convertExceptionToResponse(Exception $e)
{
if (config('app.debug')) {
$whoops = new \Whoops\Run();
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
return response()->make($whoops->handleException($e), method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500, method_exists($e, 'getHeaders') ? $e->getHeaders() : []);
}
return parent::convertExceptionToResponse($e);
}
示例4: convertExceptionToResponse
/**
* Convert the given exception into a Response instance.
*
* @param \Exception $e
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function convertExceptionToResponse(Exception $e)
{
//make sure we don't have any previous output.
//we want clean error pages so we don't confuse the user.
if (!env('APP_DEBUG')) {
ob_clean();
return response()->view('errors.500', [], 500);
}
return parent::convertExceptionToResponse($e);
}
示例5: convertExceptionToResponse
/**
* Create a Symfony response for the given exception.
*
* @param \Exception $e
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function convertExceptionToResponse(Exception $e)
{
if (config('app.debug')) {
$whoops = new Whoops();
$whoops->pushHandler(new PrettyPage());
$whoops->register();
return SymfonyResponse::create($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
}
return parent::convertExceptionToResponse($e);
}
示例6: convertExceptionToResponse
/**
* Create a Symfony response for the given exception.
*
* @param \Exception $exception
* @return Response
*/
protected function convertExceptionToResponse(Exception $exception)
{
if (App::runningInConsole()) {
// display exception response in console readable form
$message = get_class($exception) . PHP_EOL;
$message .= $exception->getMessage() . PHP_EOL . $exception->getTraceAsString();
$statusCode = FlattenException::create($exception)->getStatusCode();
return \Illuminate\Http\Response::create($message, $statusCode);
}
return parent::convertExceptionToResponse($exception);
}
示例7: _convertExceptionToResponse
protected function _convertExceptionToResponse(\Exception $exc)
{
try {
if ($exc instanceof HttpException && \Request::ajax()) {
return $this->renderHttpException($exc);
} else {
if ($this->isDebug || $exc instanceof HttpException) {
return (new ExceptionRenderer($this->isDebug))->createResponse($exc);
} else {
// try to render custom error page for HTTP status code = 500
// (by default: resources/errors/500.blade.php)
return $this->renderHttpException(new HttpException(500, $exc->getMessage(), $exc));
}
}
} catch (\Exception $exc2) {
return parent::convertExceptionToResponse($exc2);
}
}
示例8: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof AuthenticationException) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest(route('auth.login'));
}
}
// Send the response in json for ajax requests.
if ($request->ajax()) {
$error = $exception->getMessage() . ' on ' . $exception->getLine() . ' of ' . $exception->getFile();
logger()->error($exception);
return response()->json(['error' => $error], 500);
}
// If it is a redirect exception, handle the redirect.
if ($exception instanceof RedirectionExceptionInterface) {
return redirect($exception->getUrl())->with('error', $exception->getMessage());
}
// Is in debug mode, show the full whoops page.
if (config('app.debug')) {
return parent::convertExceptionToResponse($exception);
}
// Try to send the error to a custom view page.
$code = $exception->getCode();
if (view()->exists("errors.{$code}")) {
return response()->view("errors.{$code}", [], $code);
}
// If its an HTTP exception it will have a status code.
// Use that status code to render a custom view.
if ($this->isHttpException($exception)) {
$code = $exception->getStatusCode();
if (view()->exists("errors.{$code}")) {
return response()->view("errors.{$code}", [], $code);
}
return $this->renderHttpException($exception);
}
// Render it with the default laravel settings.
return parent::render($request, $exception);
}