44
55use Encore \Admin \Extension ;
66use Illuminate \Http \Request ;
7+ use Illuminate \Support \Arr ;
8+ use Throwable ;
79
810class Reporter extends Extension
911{
@@ -25,37 +27,37 @@ public function __construct(Request $request)
2527 }
2628
2729 /**
28- * @param \Exception $exception
30+ * @param Throwable $exception
2931 *
30- * @return mixed
32+ * @return void
3133 */
32- public static function report (\ Exception $ exception )
34+ public static function report (Throwable $ exception )
3335 {
3436 $ reporter = new static (request ());
3537
36- return $ reporter ->reportException ($ exception );
38+ $ reporter ->reportException ($ exception );
3739 }
3840
3941 /**
40- * @param \Exception $exception
42+ * @param Throwable $exception
4143 *
42- * @return bool
44+ * @return void
4345 */
44- public function reportException (\ Exception $ exception )
46+ public function reportException (Throwable $ exception )
4547 {
4648 $ data = [
4749
4850 // Request info.
4951 'method ' => $ this ->request ->getMethod (),
5052 'ip ' => $ this ->request ->getClientIps (),
5153 'path ' => $ this ->request ->path (),
52- 'query ' => array_except ($ this ->request ->all (), ['_pjax ' , '_token ' , '_method ' , '_previous_ ' ]),
54+ 'query ' => Arr:: except ($ this ->request ->all (), ['_pjax ' , '_token ' , '_method ' , '_previous_ ' ]),
5355 'body ' => $ this ->request ->getContent (),
5456 'cookies ' => $ this ->request ->cookies ->all (),
55- 'headers ' => array_except ($ this ->request ->headers ->all (), 'cookie ' ),
57+ 'headers ' => Arr:: except ($ this ->request ->headers ->all (), 'cookie ' ),
5658
5759 // Exception info.
58- 'exception ' => get_class ($ exception ),
60+ 'type ' => get_class ($ exception ),
5961 'code ' => $ exception ->getCode (),
6062 'file ' => $ exception ->getFile (),
6163 'line ' => $ exception ->getLine (),
@@ -67,7 +69,7 @@ public function reportException(\Exception $exception)
6769
6870 try {
6971 $ this ->store ($ data );
70- } catch (\ Exception $ e ) {
72+ } catch (Throwable $ e ) {
7173// $result = $this->reportException($e);
7274 }
7375
@@ -81,7 +83,7 @@ public function reportException(\Exception $exception)
8183 *
8284 * @return array
8385 */
84- public function stringify ($ data )
86+ public function stringify ($ data ): array
8587 {
8688 return array_map (function ($ item ) {
8789 return is_array ($ item ) ? json_encode ($ item , JSON_OBJECT_AS_ARRAY ) : (string ) $ item ;
@@ -95,30 +97,15 @@ public function stringify($data)
9597 *
9698 * @return bool
9799 */
98- public function store (array $ data )
100+ public function store (array $ data ): bool
99101 {
100- $ exception = new ExceptionModel ();
101-
102- $ exception ->type = $ data ['exception ' ];
103- $ exception ->code = $ data ['code ' ];
104- $ exception ->message = $ data ['message ' ];
105- $ exception ->file = $ data ['file ' ];
106- $ exception ->line = $ data ['line ' ];
107- $ exception ->trace = $ data ['trace ' ];
108- $ exception ->method = $ data ['method ' ];
109- $ exception ->path = $ data ['path ' ];
110- $ exception ->query = $ data ['query ' ];
111- $ exception ->body = $ data ['body ' ];
112- $ exception ->cookies = $ data ['cookies ' ];
113- $ exception ->headers = $ data ['headers ' ];
114- $ exception ->ip = $ data ['ip ' ];
115-
116102 try {
117- $ exception ->save ();
118- } catch (\Exception $ e ) {
103+ ExceptionModel::query ()->create ($ data );
104+
105+ return true ;
106+ } catch (Throwable $ e ) {
107+ return false ;
119108 //dd($e);
120109 }
121-
122- return $ exception ->save ();
123110 }
124111}
0 commit comments