Skip to content

Commit

Permalink
Catch ConnectionException
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfietje committed Feb 13, 2023
1 parent d06e3a2 commit 8375bd3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.4.4] - 2023-02-13

### Fixed

- Catch `ConnectionException`.

## [0.4.3] - 2022-11-13

### Fixed
Expand Down Expand Up @@ -86,6 +92,7 @@

- TrackPageview middleware.

[0.4.4]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.4
[0.4.3]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.3
[0.4.2]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.2
[0.4.1]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.1
Expand Down
48 changes: 26 additions & 22 deletions src/Pirsch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pirsch;

use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;

class Pirsch
Expand All @@ -15,28 +16,31 @@ public static function track(
return;
}

Http::withToken(config('pirsch.token'))
->retry(
times: 3,
sleepMilliseconds: 100,
throw: false,
)
->post(
url: 'https://api.pirsch.io/api/v1/'.($name === null ? 'hit' : 'event'),
data: [
'url' => request()->fullUrl(),
'ip' => request()->ip(),
'user_agent' => request()->userAgent(),
'accept_language' => request()->header('Accept-Language'),
'referrer' => request()->header('Referer'),
...$name === null
? []
: [
'event_name' => $name,
'event_meta' => $meta,
],
],
);
try {
Http::withToken(config('pirsch.token'))
->retry(
times: 3,
sleepMilliseconds: 100,
throw: false,
)
->post(
url: 'https://api.pirsch.io/api/v1/'.($name === null ? 'hit' : 'event'),
data: [
'url' => request()->fullUrl(),
'ip' => request()->ip(),
'user_agent' => request()->userAgent(),
'accept_language' => request()->header('Accept-Language'),
'referrer' => request()->header('Referer'),
...$name === null
? []
: [
'event_name' => $name,
'event_meta' => $meta,
],
],
);
} catch (ConnectionException) {
}
});
}
}

0 comments on commit 8375bd3

Please sign in to comment.