- $response = $httpClient->send($request);
- if ($response->getStatusCode() >= 400) {
- Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with status {$response->getStatusCode()}");
- }
- } catch (ClientExceptionInterface $exception) {
- Log::error("Received error during webhook call to endpoint {$this->webhook->endpoint}: {$exception->getMessage()}");
+ $response = Http::asJson()
+ ->withOptions(['allow_redirects' => ['strict' => true]])
+ ->timeout($this->webhook->timeout)
+ ->post($this->webhook->endpoint, $webhookData);
+ } catch (\Exception $exception) {
+ $lastError = $exception->getMessage();
+ Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with error \"{$lastError}\"");
+ }
+
+ if (isset($response) && $response->failed()) {
+ $lastError = "Response status from endpoint was {$response->status()}";
+ Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with status {$response->status()}");