Enable the feature flag for telemetry.

This commit is contained in:
James Cole
2020-05-24 12:00:14 +02:00
parent 61733f6553
commit be58b1d2be
6 changed files with 54 additions and 13 deletions

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Jobs;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Telemetry;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
@@ -33,7 +34,9 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use JsonException;
use Log;
use Exception;
/**
* Class SubmitTelemetryData
@@ -61,7 +64,7 @@ class SubmitTelemetryData implements ShouldQueue
}
/**
*
* @throws FireflyException
*/
public function handle(): void
{
@@ -76,10 +79,19 @@ class SubmitTelemetryData implements ShouldQueue
return;
}
$body = '[]';
$json = $this->parseJson($telemetry);
try {
json_encode($json, JSON_THROW_ON_ERROR, 512);
} catch (JsonException $e) {
Log::error($e->getMessage());
Log::error('Could not parse JSON.');
throw new FireflyException(sprintf('Could not parse telemetry JSON: %s', $e->getMessage()));
}
$client = new Client;
$options = [
'body' => json_encode($json, JSON_THROW_ON_ERROR, 512),
'body' => $body,
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
@@ -89,11 +101,11 @@ class SubmitTelemetryData implements ShouldQueue
];
try {
$result = $client->post($url, $options);
} catch (GuzzleException $e) {
} catch (GuzzleException|Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
Log::error('Could not submit telemetry.');
return;
throw new FireflyException(sprintf('Could not submit telemetry: %s', $e->getMessage()));
}
$body = (string) $result->getBody();
$statusCode = $result->getStatusCode();