I use the Laravel framework. When I get an exception GuzzleHttp\\Exception\\ClientException(code: 404)
, this event is added to laravel.log. How can I disable adding the event about that error to laravel.log?
CodePudding user response:
You can remove it from the exceptions handler file according to the docs, if can be found in your App\Exceptions\Handler
so for example:-
use GuzzleHttp\Exception\ClientException; // here, import the target class
...
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var string[]
*/
protected $dontReport = [
ClientException::class, // here, add the class to the don't report list
];
...
}
to manipulate a custom error condition, you can register it in the register method in the Handler file like:-
**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
// check if the ClientExeption is a 404
$this->reportable(function (ClientException $e) {
if ($e->getCode() == 404) {
return false; // or anything else for that matter
}
});
}