Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions app/Jobs/Speedtests/ExecuteOoklaSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,34 @@ public function handle(): void
} catch (ProcessFailedException $exception) {
$messages = explode(PHP_EOL, $exception->getMessage());

$message = collect(array_filter($messages, 'json_validate'))->last();

// Extract only the "message" part from each JSON error message
$errorMessages = array_map(function ($message) {
$decoded = json_decode($message, true);
if (json_last_error() === JSON_ERROR_NONE && isset($decoded['message'])) {
return $decoded['message'];
}

return ''; // If it's not valid JSON or doesn't contain "message", return an empty string
}, $messages);

// Filter out empty messages and concatenate
$errorMessage = implode(' | ', array_filter($errorMessages));

// Prepare the error message data
$data = [
'type' => 'log',
'level' => 'error',
'message' => $errorMessage,
];

// Add server ID if it exists
if ($this->serverId !== null) {
$data['server'] = ['id' => $this->serverId];
}

// Update the result with the error data
$this->result->update([
'server_id' => $this->serverId,
'data' => json_decode($message, true),
'data' => $data,
'status' => ResultStatus::Failed,
]);

Expand All @@ -87,6 +110,9 @@ public function handle(): void
SpeedtestCompleted::dispatch($this->result);
}

/**
* Check for internet connection.
*/
protected function checkForInternetConnection(): bool
{
$url = config('speedtest.ping_url');
Expand All @@ -98,7 +124,6 @@ protected function checkForInternetConnection(): bool

if (! URL::isValidUrl($url)) {
$this->result->update([
'server_id' => $this->serverId,
'data' => [
'type' => 'log',
'level' => 'error',
Expand All @@ -122,7 +147,6 @@ protected function checkForInternetConnection(): bool

if ($ping->ping() === false) {
$this->result->update([
'server_id' => $this->serverId,
'data' => [
'type' => 'log',
'level' => 'error',
Expand Down