我正在尝试追踪向我的服务器发出请求的外部 API 的一个非常具体的问题。如何更改异常处理程序以便将请求验证异常记录在错误日志文件中?预先感谢您的帮助。
前往您的
app/Exceptions/Handler.php
编辑
register
方法:
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
if ($e instanceof ValidationException) {
Log::error($e->getMessage(), $this->buildExceptionContext($e));
}
});
}
现在,每当发生验证错误时,都会将其写入您的日志,而不会更改向最终用户报告的方式。