本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\NotFoundHttpException::getCode方法的典型用法代码示例。如果您正苦于以下问题:PHP NotFoundHttpException::getCode方法的具体用法?PHP NotFoundHttpException::getCode怎么用?PHP NotFoundHttpException::getCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Exception\NotFoundHttpException
的用法示例。
在下文中一共展示了NotFoundHttpException::getCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
{
\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);
}
示例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)
{
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);
}
示例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);
} elseif ($e instanceof ApiException) {
return response()->json(['error' => true, 'message_info' => $e->getMessage()], $e->getCode());
}
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);
}
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);
}
示例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);
}
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);
}