【发布时间】:2019-10-22 08:15:30
【问题描述】:
我正在处理Handler.php 的异常,但是当我故意引发某些异常时,report 方法不仅会写入该异常,而且还会写入至少 24 次相同的Session store error,因为我正在使用会话以检索自定义错误消息。我的报告方法只有默认的parent::report($exception);。日志写了我故意犯的查询错误,还有很多Session store error
//render method at Handler.php
public function render($request, Exception $exception)
{
if($request->session()->has('errorOrigin'))
{
$errorOrigin = $request->session()->pull('errorOrigin');
} else{
$errorOrigin = "";
}
//session()->forget('errorOrigin');
//return dd(session());
//return parent::render($request, $exception);
//this return is just some trying
//return parent::render($request, $exception);
//return dd($exception);
//return parent::render($request, $exception);
//just in case someone throws it but don´t has the try catch at the code
if($exception instanceof \App\Exceptions\CustomException) {
//$request->session()->flash('message_type', 'negative');
\Session::flash('message_type', 'negative');
\Session::flash('message_icon', 'hide');
\Session::flash('message_header', 'Success');
\Session::flash('error', '¡Ha ocurrido un error ' . $errorOrigin . "!"
.' Si este persiste contacte al administrador del sistema');
return redirect()->back();
}elseif($exception instanceof \Illuminate\Database\QueryException) {
\Session::flash('message_type', 'negative');
\Session::flash('message_icon', 'hide');
\Session::flash('message_header', 'Success');
\Session::flash('error', '¡Ha ocurrido un error en la consulta ' . $errorOrigin);//this is he customized error message
return back();
}else{/*Original error handling*/
return parent::render($request, $exception);
}
}
//Method at my controller
public function index(Request $request)
{
//custom message if this methods throw an exception
\Session::put('errorOrigin', " mostrando los clientes");
//on purpose error, that table doesn´t exist, so it causes the QueryException error
DB::table('shdhgjd')->get();
}
我认为检索到的所有\Session 或errorOrigin 变量都会创建错误Session store error,但我需要它们,是否存在逻辑/语法错误?我需要一些帮助,因为日志越来越大,保存所有这些错误没有意义,也不保存它们。
还发现这个错误发生在每个页面上,登录时的事件。我使用用户名而不是电子邮件登录(当然登录已经有效,并且使用用户名正确登录)。它与它有什么关系吗?我没有做任何事情就刷新了登录页面,而不是尝试登录的事件,它还在我的日志中保存了一个错误,但我的应用程序继续工作。
这次我故意从不存在的数据库表中引发错误,这是我一次引发错误时保存到日志中的错误摘要。正如您将看到的,会话存储错误或类似的重复,但有些显示未捕获的RunTimeException。还添加了最后一个的堆栈跟踪。会话存储错误至少重复 24 次甚至更多。
[2019-06-06 19:55:59] local.ERROR: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'prisma.shdhgjd' doesn't exist (SQL: select * from `shdhgjd`)
[2019-06-06 19:56:00] local.ERROR: Session store not set on request. {"exception":"[object] (RuntimeException(code: 0): Session store not set on request. at C:\\ProyectoPrisma_BS3\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Request.php:419)
[stacktrace]
"#0" C:\\ProyectoPrisma_BS3\\app\\Exceptions\\Handler.php(69): Illuminate\\Http\\Request->session()
[2019-06-06 19:56:00] local.ERROR: Session store not set on request. {"exception":"[object] (RuntimeException(code: 0): Session store not set on request. at C:\\ProyectoPrisma_BS3\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Request.php:419)
[stacktrace]
[2019-06-06 19:56:00] local.ERROR: Uncaught RuntimeException: Session store not set on request. in C:\ProyectoPrisma_BS3\vendor\laravel\framework\src\Illuminate\Http\Request.php:419
Stack trace:
"#0" C:\ProyectoPrisma_BS3\app\Exceptions\Handler.php(69): Illuminate\Http\Request->session()
【问题讨论】:
-
“会话存储错误”是生成的确切错误消息吗?如果没有,你能分享一下确切的信息吗?
-
@AkenRoberts,当我只导致一次查询异常时,已经上传了一小部分错误。感谢您的帮助!
-
听起来该类无法访问 Session 并抛出一个错误循环,试图使用 back 将数据闪存到会话中。相反,请检查是否有
$request->session()->has('_previous')然后您可以重定向到$request->session()->get('_previous')['url']请参阅本节中的警告:laravel.com/docs/5.8/redirects#creating-redirects -
@j.steelman 谢谢,但遗憾的是没有工作。但我发现一些有趣的事情发生在所有页面上,甚至在登录时(只是进入登录视图,而不是尝试记录的事件)。我会在问题本身更新一些信息。
标签: php laravel session report session-variables