From 47a77eabf2d85152f370d2daa15a70b5fc7d57d7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Oct 2023 15:06:08 -0700 Subject: [PATCH] Avoid logging error messages for webhook request failures --- app/Listeners/CheckoutableListener.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index d9680f82a..13579ce6b 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -18,6 +18,7 @@ use App\Notifications\CheckoutAccessoryNotification; use App\Notifications\CheckoutAssetNotification; use App\Notifications\CheckoutConsumableNotification; use App\Notifications\CheckoutLicenseSeatNotification; +use GuzzleHttp\Exception\ClientException; use Illuminate\Support\Facades\Notification; use Exception; use Log; @@ -61,6 +62,16 @@ class CheckoutableListener ); } } catch (Exception $e) { + if ($e instanceof ClientException){ + $statusCode = $e->getResponse()->getStatusCode(); + // If status code is in 400 range, we don't want to log it as an error + // @todo: 300 and 500 as well? + if ($statusCode >= 400 && $statusCode < 500) { + Log::debug("Exception caught during checkout notification: ".$e->getMessage()); + return; + } + } + Log::error("Exception caught during checkout notification: ".$e->getMessage()); } }