Skip to content

A free open source IT asset/license management system

log warnings instead of errors for 4xx status codes

Godfrey M0ab206ca13f5
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 908dd58dfd..6c231a6c38 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -39,6 +39,7 @@ use Exception;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Osama\LaravelTeamsNotification\TeamsNotification;
+use function Laravel\Prompts\error;
class CheckoutableListener
{
@@ -128,11 +129,18 @@ class CheckoutableListener
->notify($this->getCheckoutNotification($event, $acceptance));
}
} catch (ClientException $e) {
+ $status = optional($e->getResponse()->getStatusCode());
+
if (strpos($e->getMessage(), 'channel_not_found') !== false) {
Log::warning(Setting::getSettings()->webhook_selected . " notification failed: " . $e->getMessage());
return redirect()->back()->with('warning', ucfirst(Setting::getSettings()->webhook_selected) . trans('admin/settings/message.webhook.webhook_channel_not_found'));
} else {
- Log::error("ClientException caught during checkin notification: " . $e->getMessage());
+ if ($status >= 500 || $status === null) {
+ Log:error(Setting::getSettings()->webhook_selected . " notification failed: " . $e->getMessage());
+ } else {
+ Log::warning("ClientException caught during checkin notification: " . $e->getMessage());
+ return redirect()->back()->with('warning', ucfirst(Setting::getSettings()->webhook_selected) . trans('admin/settings/message.webhook.webhook_fail'));
+ }
}
return redirect()->back()->with('warning', ucfirst(Setting::getSettings()->webhook_selected) . trans('admin/settings/message.webhook.webhook_fail'));
} catch (Exception $e) {
@@ -224,12 +232,18 @@ class CheckoutableListener
->notify($this->getCheckinNotification($event));
}
} catch (ClientException $e) {
+ $status = optional($e->getResponse()->getStatusCode());
+
if (strpos($e->getMessage(), 'channel_not_found') !== false) {
Log::warning(Setting::getSettings()->webhook_selected . " notification failed: " . $e->getMessage());
return redirect()->back()->with('warning', ucfirst(Setting::getSettings()->webhook_selected) . trans('admin/settings/message.webhook.webhook_channel_not_found'));
} else {
- Log::error("ClientException caught during checkin notification: " . $e->getMessage());
- return redirect()->back()->with('warning', ucfirst(Setting::getSettings()->webhook_selected) . trans('admin/settings/message.webhook.webhook_fail'));
+ if ($status >= 500 || $status === null) {
+ Log:error(Setting::getSettings()->webhook_selected . " notification failed: " . $e->getMessage());
+ } else {
+ Log::warning("ClientException caught during checkin notification: " . $e->getMessage());
+ return redirect()->back()->with('warning', ucfirst(Setting::getSettings()->webhook_selected) . trans('admin/settings/message.webhook.webhook_fail'));
+ }
}
} catch (Exception $e) {
Log::warning(ucfirst(Setting::getSettings()->webhook_selected) . ' webhook notification failed:', [