fix: added logs instead of exception
This commit is contained in:
2 files changed
+43
-13
No files matched your search
@@ -3,7 +3,7 @@
|
||||
namespace Mattitja\Analytics\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use InvalidArgumentException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AnalyticsClient
|
||||
{
|
||||
@@ -26,12 +26,12 @@ class AnalyticsClient
|
||||
* Send analytics data to the Mattitja Analytics API.
|
||||
*
|
||||
* @param array $data Analytics data payload
|
||||
*
|
||||
* @throws InvalidArgumentException If required fields are missing
|
||||
*/
|
||||
public function send(array $data): void
|
||||
{
|
||||
$this->validateData($data);
|
||||
if (! $this->validateData($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cleanData = $this->cleanData($data);
|
||||
|
||||
@@ -47,21 +47,33 @@ class AnalyticsClient
|
||||
* Validate that all required fields are present and not empty.
|
||||
*
|
||||
* @param array $data Analytics data to validate
|
||||
*
|
||||
* @throws InvalidArgumentException If required fields are missing
|
||||
* @return bool True if valid, false otherwise
|
||||
*/
|
||||
protected function validateData(array $data): void
|
||||
protected function validateData(array $data): bool
|
||||
{
|
||||
foreach (self::REQUIRED_FIELDS as $field) {
|
||||
if (! isset($data[$field])) {
|
||||
throw new InvalidArgumentException("Required field '{$field}' is missing");
|
||||
Log::warning("Analytics: Required field '{$field}' is missing");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// User agent can be empty string, but other fields cannot
|
||||
if ($field !== 'ua' && empty($data[$field])) {
|
||||
throw new InvalidArgumentException("Required field '{$field}' cannot be empty");
|
||||
Log::warning("Analytics: Required field '{$field}' cannot be empty");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// URL max length check (API spec: max 512 characters)
|
||||
if (isset($data['u']) && strlen($data['u']) > 512) {
|
||||
Log::warning('Analytics: URL exceeds 512 characters, skipping');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user