1+ <?php
2+
3+ namespace Mamikos \Tikus ;
4+
5+ use Throwable ;
6+ use Exception ;
7+ use Bugsnag \BugsnagLaravel \Facades \Bugsnag ;
8+ use Sentry \Laravel \Facade as Sentry ;
9+
10+ class Tikus
11+ {
12+ public function reportException (Throwable $ throwable , Array $ metadata = [])
13+ {
14+ try {
15+ if (empty ($ metadata ) === false )
16+ {
17+ Sentry::configureScope (function ($ scope ) use ($ metadata ) {
18+ try {
19+ $ scope ->setContext ('metadata ' , $ metadata );
20+ }
21+ catch (Exception $ e )
22+ {
23+ $ scope ->setContext ('metadata ' , [
24+ 'error in set metadata ' => $ e ->getMessage ()
25+ ]);
26+ }
27+ });
28+ }
29+
30+ Sentry::captureException ($ throwable );
31+ }
32+ catch (Exception $ e ) {}
33+
34+ try {
35+ // Bugsnag
36+ if (empty ($ metadata ) === true )
37+ {
38+ Bugsnag::notifyException ($ throwable );
39+ }
40+ else
41+ {
42+ Bugsnag::notifyException ($ throwable , function ($ report ) use ($ metadata ) {
43+ try {
44+ $ report ->setMetaData ($ metadata );
45+ }
46+ catch (Exception $ e )
47+ {
48+ $ report ->setMetaData ([
49+ 'error in set metadata ' => $ e ->getMessage ()
50+ ]);
51+ }
52+ });
53+ }
54+ }
55+ catch (Exception $ e ) {}
56+ }
57+
58+ public function reportError ($ name , $ message , Array $ metadata = [])
59+ {
60+ try {
61+ // Sentry
62+ if (empty ($ metadata ) === false )
63+ {
64+ Sentry::configureScope (function ($ scope ) use ($ metadata ) {
65+ try {
66+ $ scope ->setContext ('metadata ' , $ metadata );
67+ }
68+ catch (Exception $ e )
69+ {
70+ $ scope ->setContext ('metadata ' , [
71+ 'error in set metadata ' => $ e ->getMessage ()
72+ ]);
73+ }
74+ });
75+ }
76+ Sentry::captureMessage ("[ {$ name }] {$ message }" );
77+ }
78+ catch (Exception $ e ) {}
79+
80+ try {
81+ // Bugsnag
82+ if (empty ($ metadata ) === true )
83+ {
84+ Bugsnag::notifyError ($ name , $ message );
85+ }
86+ else
87+ {
88+ Bugsnag::notifyError ($ name , $ message , function ($ report ) use ($ metadata ) {
89+ try {
90+ $ report ->setMetaData ($ metadata );
91+ }
92+ catch (Exception $ e )
93+ {
94+ $ report ->setMetaData ([
95+ 'error in set metadata ' => $ e ->getMessage ()
96+ ]);
97+ }
98+ });
99+ }
100+ }
101+ catch (Exception $ e ) {}
102+ }
103+ }
0 commit comments