Skip to content

Commit 8375bd3

Browse files
committed
Catch ConnectionException
1 parent d06e3a2 commit 8375bd3

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.4.4] - 2023-02-13
4+
5+
### Fixed
6+
7+
- Catch `ConnectionException`.
8+
39
## [0.4.3] - 2022-11-13
410

511
### Fixed
@@ -86,6 +92,7 @@
8692

8793
- TrackPageview middleware.
8894

95+
[0.4.4]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.4
8996
[0.4.3]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.3
9097
[0.4.2]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.2
9198
[0.4.1]: https://github.com/pirsch-analytics/laravel-pirsch/releases/tag/0.4.1

src/Pirsch.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pirsch;
44

5+
use Illuminate\Http\Client\ConnectionException;
56
use Illuminate\Support\Facades\Http;
67

78
class Pirsch
@@ -15,28 +16,31 @@ public static function track(
1516
return;
1617
}
1718

18-
Http::withToken(config('pirsch.token'))
19-
->retry(
20-
times: 3,
21-
sleepMilliseconds: 100,
22-
throw: false,
23-
)
24-
->post(
25-
url: 'https://api.pirsch.io/api/v1/'.($name === null ? 'hit' : 'event'),
26-
data: [
27-
'url' => request()->fullUrl(),
28-
'ip' => request()->ip(),
29-
'user_agent' => request()->userAgent(),
30-
'accept_language' => request()->header('Accept-Language'),
31-
'referrer' => request()->header('Referer'),
32-
...$name === null
33-
? []
34-
: [
35-
'event_name' => $name,
36-
'event_meta' => $meta,
37-
],
38-
],
39-
);
19+
try {
20+
Http::withToken(config('pirsch.token'))
21+
->retry(
22+
times: 3,
23+
sleepMilliseconds: 100,
24+
throw: false,
25+
)
26+
->post(
27+
url: 'https://api.pirsch.io/api/v1/'.($name === null ? 'hit' : 'event'),
28+
data: [
29+
'url' => request()->fullUrl(),
30+
'ip' => request()->ip(),
31+
'user_agent' => request()->userAgent(),
32+
'accept_language' => request()->header('Accept-Language'),
33+
'referrer' => request()->header('Referer'),
34+
...$name === null
35+
? []
36+
: [
37+
'event_name' => $name,
38+
'event_meta' => $meta,
39+
],
40+
],
41+
);
42+
} catch (ConnectionException) {
43+
}
4044
});
4145
}
4246
}

0 commit comments

Comments
 (0)