File: /home/xedaptot/ai.naniguide.com/app/Notifications/Admin/SendingServerWebhookProcessingFailed.php
<?php
namespace App\Notifications\Admin;
use App\Model\SendingServer;
use App\Notifications\AppNotification;
use Illuminate\Database\Eloquent\Model;
use Throwable;
/**
* Listener (RecordBounce / RecordComplaint / ConfirmSnsSubscription) threw
* while processing a webhook. Includes exception class + message + first
* 4 KB of trace so admin can debug from the inbox.
*/
class SendingServerWebhookProcessingFailed extends AppNotification
{
public function __construct(
public SendingServer $server,
public string $kind, // 'bounce' | 'complaint' | 'handshake'
public string $errorClass,
public string $errorMessage,
public ?string $errorTrace = null,
public ?string $runtimeMessageId = null,
public ?string $rawPreview = null
) {}
public static function fromException(
SendingServer $server,
string $kind,
Throwable $e,
?string $runtimeMessageId = null,
?string $rawPreview = null
): self {
return new self(
$server,
$kind,
get_class($e),
$e->getMessage(),
substr($e->getTraceAsString(), 0, 4000),
$runtimeMessageId,
$rawPreview
);
}
public function audience(): string { return self::AUDIENCE_ADMINS; }
public function category(): string { return self::CATEGORY_ALERT; }
public function severity(): string { return self::SEVERITY_ERROR; }
public function subject(): ?Model
{
return $this->server;
}
public function toArray(object $notifiable = null): array
{
return [
'title' => sprintf('Webhook %s processing FAILED', $this->kind),
'body' => sprintf(
'%s server "%s" — %s: %s%s',
$this->server->type,
$this->server->name ?? ('#' . $this->server->id),
$this->errorClass,
$this->errorMessage,
$this->runtimeMessageId ? ' (runtime_message_id=' . $this->runtimeMessageId . ')' : ''
),
'meta' => [
'trace' => $this->errorTrace,
'raw' => $this->rawPreview,
],
];
}
}