本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\HttpException::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpException::getResponse方法的具体用法?PHP HttpException::getResponse怎么用?PHP HttpException::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Exception\HttpException
的用法示例。
在下文中一共展示了HttpException::getResponse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* 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);
}
}
示例2: render
/**
* Render an exception into an HTTP response. Should conform to RFC "Problem Details for HTTP APIs":
* https://tools.ietf.org/html/rfc7807
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof HttpResponseException) {
// return $e->getResponse();
$title = 'An exception happened when preparing the HTTP response';
} elseif ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
$statusCode = HttpStatus::NotFound;
$title = 'The entity does not exist';
} elseif ($e instanceof AuthorizationException) {
$e = new HttpException(HttpStatus::Forbidden, $e->getMessage());
$title = 'You are not authorized to access this information';
} elseif ($e instanceof ValidationException && $e->getResponse()) {
$errors = json_decode($e->getResponse()->content());
$statusCode = HttpStatus::UnprocessableEntity;
$title = 'Data validation error';
}
$response = [];
/* $response = [
'type' => '',
'title' => 'Something went wrong',
'detail' => $e->getMessage() ?: 'No more information is known',
'instance' => ''
]; */
if (isset($title)) {
$response['title'] = $title;
}
if ($e->getMessage()) {
$response['detail'] = $e->getMessage();
}
if (isset($errors)) {
$response['invalid-fields'] = $errors;
}
if (env('APP_DEBUG', false)) {
$response['debug'] = ['exception' => get_class($e), 'trace' => $e->getTrace(), 'response' => method_exists($e, 'getResponse') ? $e->getResponse() : ''];
}
if (!isset($statusCode)) {
if (method_exists($e, 'getStatusCode')) {
$statusCode = $e->getStatusCode();
} else {
$statusCode = HttpStatus::InternalServerError;
}
}
return response()->json($response, $statusCode);
// return parent::render($request, $e);
}
示例3: render
/**
* 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 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();
}
$fe = FlattenException::create($e);
$handler = new SymfonyExceptionHandler(env('APP_DEBUG', false));
$decorated = $this->decorate($handler->getContent($fe), $handler->getStylesheet($fe));
$response = new Response($decorated, $fe->getStatusCode(), $fe->getHeaders());
$response->exception = $e;
return $response;
}
示例4: render
/**
* 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)
{
$fullurl = $request->fullUrl();
if (isset(Auth::User()->name)) {
$username = Auth::User()->name;
} else {
$username = 'Unknown user';
}
$ip_address = 'Unspecified IP Address';
if (!empty($request->ip())) {
$ip_address = $request->ip();
}
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof AuthorizationException) {
$e = new HttpException(403, $e->getMessage());
} elseif ($e instanceof ValidationException && $e->getResponse()) {
return $e->getResponse();
}
$e->debug = TRUE;
if ($this->isHttpException($e)) {
return $this->toIlluminateResponse($this->renderHttpException($e), $e);
} else {
Mail::send('emails.error', ['error' => $this->convertExceptionToResponse($e)], function ($message) use($fullurl, $username, $ip_address) {
$message->to('anthony.borrow@montserratretreat.org');
$message->subject('Polanco Error @' . $fullurl . ' by: ' . $username . ' from: ' . $ip_address);
$message->from('polanco@montserratretreat.org');
});
return view('errors.default');
}
}
示例5: render
/**
* Render an exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
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 {
return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
}
}
示例6: renderException
protected function renderException($request, $e)
{
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();
}
$fe = FlattenException::create($e);
$data = env("APP_DEBUG", false) ? $fe->toArray() : ["message" => "whoops, something wrong."];
return $this->response()->error($data);
}