@@ -61,11 +61,34 @@ public function handle(): void
6161 } catch (ProcessFailedException $ exception ) {
6262 $ messages = explode (PHP_EOL , $ exception ->getMessage ());
6363
64- $ message = collect (array_filter ($ messages , 'json_validate ' ))->last ();
65-
64+ // Extract only the "message" part from each JSON error message
65+ $ errorMessages = array_map (function ($ message ) {
66+ $ decoded = json_decode ($ message , true );
67+ if (json_last_error () === JSON_ERROR_NONE && isset ($ decoded ['message ' ])) {
68+ return $ decoded ['message ' ];
69+ }
70+
71+ return '' ; // If it's not valid JSON or doesn't contain "message", return an empty string
72+ }, $ messages );
73+
74+ // Filter out empty messages and concatenate
75+ $ errorMessage = implode (' | ' , array_filter ($ errorMessages ));
76+
77+ // Prepare the error message data
78+ $ data = [
79+ 'type ' => 'log ' ,
80+ 'level ' => 'error ' ,
81+ 'message ' => $ errorMessage ,
82+ ];
83+
84+ // Add server ID if it exists
85+ if ($ this ->serverId !== null ) {
86+ $ data ['server ' ] = ['id ' => $ this ->serverId ];
87+ }
88+
89+ // Update the result with the error data
6690 $ this ->result ->update ([
67- 'server_id ' => $ this ->serverId ,
68- 'data ' => json_decode ($ message , true ),
91+ 'data ' => $ data ,
6992 'status ' => ResultStatus::Failed,
7093 ]);
7194
@@ -87,6 +110,9 @@ public function handle(): void
87110 SpeedtestCompleted::dispatch ($ this ->result );
88111 }
89112
113+ /**
114+ * Check for internet connection.
115+ */
90116 protected function checkForInternetConnection (): bool
91117 {
92118 $ url = config ('speedtest.ping_url ' );
@@ -98,7 +124,6 @@ protected function checkForInternetConnection(): bool
98124
99125 if (! URL ::isValidUrl ($ url )) {
100126 $ this ->result ->update ([
101- 'server_id ' => $ this ->serverId ,
102127 'data ' => [
103128 'type ' => 'log ' ,
104129 'level ' => 'error ' ,
@@ -122,7 +147,6 @@ protected function checkForInternetConnection(): bool
122147
123148 if ($ ping ->ping () === false ) {
124149 $ this ->result ->update ([
125- 'server_id ' => $ this ->serverId ,
126150 'data ' => [
127151 'type ' => 'log ' ,
128152 'level ' => 'error ' ,
0 commit comments