feat: add error_context column to post_platforms for structured error debugging
This commit is contained in:
parent
5903f0d894
commit
8e33f9ce4f
3 changed files with 48 additions and 5 deletions
|
|
@ -103,12 +103,22 @@ public function handle(): void
|
|||
'platform_error_code' => $e->platformErrorCode,
|
||||
]);
|
||||
|
||||
$this->postPlatform->markAsFailed($e->getMessage());
|
||||
$this->postPlatform->markAsFailed($e->getMessage(), [
|
||||
'category' => 'token_expired',
|
||||
'platform_error_code' => $e->platformErrorCode,
|
||||
'failed_at' => now()->toIso8601String(),
|
||||
]);
|
||||
$this->postPlatform->socialAccount->markAsDisconnected($e->getMessage());
|
||||
break;
|
||||
} catch (SocialPublishException $e) {
|
||||
Log::error('Social publish failed: '.$e->userMessage);
|
||||
$this->postPlatform->markAsFailed($e->userMessage);
|
||||
$this->postPlatform->markAsFailed($e->userMessage, [
|
||||
'category' => $e->category->value,
|
||||
'platform_error_code' => $e->platformErrorCode,
|
||||
'failed_at' => now()->toIso8601String(),
|
||||
'content_length' => mb_strlen($this->postPlatform->content ?? ''),
|
||||
'media_count' => $this->postPlatform->media->count(),
|
||||
]);
|
||||
break;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Failed to publish to social platform', [
|
||||
|
|
@ -116,7 +126,12 @@ public function handle(): void
|
|||
'platform' => $this->postPlatform->platform->value,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
$this->postPlatform->markAsFailed($e->getMessage());
|
||||
$this->postPlatform->markAsFailed($e->getMessage(), [
|
||||
'category' => 'unknown',
|
||||
'failed_at' => now()->toIso8601String(),
|
||||
'content_length' => mb_strlen($this->postPlatform->content ?? ''),
|
||||
'media_count' => $this->postPlatform->media->count(),
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +239,10 @@ public function failed(?\Throwable $exception): void
|
|||
$this->postPlatform->refresh();
|
||||
|
||||
if ($this->postPlatform->status !== PostPlatformStatus::Published) {
|
||||
$this->postPlatform->markAsFailed($exception?->getMessage() ?? 'Unknown error');
|
||||
$this->postPlatform->markAsFailed($exception?->getMessage() ?? 'Unknown error', [
|
||||
'category' => 'job_failed',
|
||||
'failed_at' => now()->toIso8601String(),
|
||||
]);
|
||||
$this->updatePostStatus();
|
||||
$this->broadcastStatus();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class PostPlatform extends Model
|
|||
'platform_post_id',
|
||||
'platform_url',
|
||||
'error_message',
|
||||
'error_context',
|
||||
'published_at',
|
||||
'meta',
|
||||
];
|
||||
|
|
@ -43,6 +44,7 @@ protected function casts(): array
|
|||
'status' => Status::class,
|
||||
'published_at' => 'datetime',
|
||||
'meta' => 'array',
|
||||
'error_context' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -71,11 +73,12 @@ public function markAsPublished(string $platformPostId, ?string $platformUrl = n
|
|||
]);
|
||||
}
|
||||
|
||||
public function markAsFailed(string $errorMessage): void
|
||||
public function markAsFailed(string $errorMessage, ?array $errorContext = null): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => Status::Failed,
|
||||
'error_message' => $errorMessage,
|
||||
'error_context' => $errorContext,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('post_platforms', function (Blueprint $table) {
|
||||
$table->json('error_context')->nullable()->after('error_message');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('post_platforms', function (Blueprint $table) {
|
||||
$table->dropColumn('error_context');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue