【发布时间】:2019-10-24 10:28:31
【问题描述】:
我有一个 laravel 5.7 应用程序,当我停用调试模式时,内部服务器错误页面一直显示异常消息,而不是一般消息“糟糕,我们的服务器出了点问题!”。
这里是异常处理程序的代码:
<?php
namespace App\Exceptions;
use Doctrine\DBAL\Query\QueryException;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
\Illuminate\Database\QueryException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}
/**
* 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)
{
return parent::render($request, $exception);
}
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest('login');
}
}
我没有自定义 500 错误视图,并且默认情况下是异常处理程序。 有谁知道为什么会这样?
最好的问候
【问题讨论】:
-
在
.env文件中你确定APP_DEBUG等于true? -
APP_DEBUG 为假,我不想激活 degu 模式。我只是不想让用户在前端看到异常消息。
-
请提供
app/Exceptions/Handler.php的代码 -
Exceptions\Handler 代码添加到问题@SerhiiPosternak
标签: laravel laravel-5.7 internal-server-error