A free open source IT asset/license management system
add a try catch to ms teams audit notification
Godfrey Mced83b9bfc52
diff --git a/app/Models/Traits/Loggable.php b/app/Models/Traits/Loggable.phpindex 4ea08c1525..95d9a14d4b 100644--- a/app/Models/Traits/Loggable.php+++ b/app/Models/Traits/Loggable.php@@ -10,10 +10,13 @@ use App\Models\Location;use App\Models\Setting;use App\Models\User;use App\Notifications\AuditNotification;+use GuzzleHttp\Exception\ConnectException;+use GuzzleHttp\Exception\RequestException;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\Log;use Illuminate\Support\Str;use Osama\LaravelTeamsNotification\TeamsNotification;+use Throwable;trait Loggable{@@ -282,10 +285,28 @@ trait Loggable'location' => ($location) ? $location->name : '','note' => $note,];+if(Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {- $message = AuditNotification::toMicrosoftTeams($params);- $notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);- $notification->success()->sendMessage($message[0], $message[1]);+ try {+ $endpoint = Setting::getSettings()->webhook_endpoint;+ $message = AuditNotification::toMicrosoftTeams($params);+ $notification = new TeamsNotification($endpoint);++ $notification->success()->sendMessage($message[0], $message[1]);++ } catch (ConnectException $e) {+ Log::warning('Teams webhook connection failed', [+ 'endpoint' => Setting::getSettings()->webhook_endpoint,+ 'error' => $e->getMessage(),+ ]);++ } catch (Throwable $e) {+ Log::error('Teams webhook failed unexpectedly', [+ 'endpoint' => Setting::getSettings()->webhook_endpoint,+ 'exception' => get_class($e),+ 'error' => $e->getMessage(),+ ]);+ }}else {Setting::getSettings()->notify(new AuditNotification($params));