本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\NotFoundHttpException::getMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP NotFoundHttpException::getMessage方法的具体用法?PHP NotFoundHttpException::getMessage怎么用?PHP NotFoundHttpException::getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Exception\NotFoundHttpException
的用法示例。
在下文中一共展示了NotFoundHttpException::getMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* 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);
}
示例2: 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)
{
\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);
}
示例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 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);
}
示例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)
{
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);
}
示例5: 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 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);
}
示例6: 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 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);
}
示例7: 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)
{
$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);
}
示例8: 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 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);
}
示例9: 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 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);
}
示例10: 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 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);
}
}
示例11: 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 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);
}
示例12: 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 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);
}
示例13: 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 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);
}
示例14: 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 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);
}
示例15: 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 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);
}