@@ -116,17 +116,24 @@ protected function fetchNewSessionToken()
116
116
];
117
117
118
118
// perform the login
119
- $ response = Http::retry ($ this ->attempts , 100 )->withBasicAuth ($ this ->config ['username ' ], $ this ->config ['password ' ])
120
- ->post ($ url , $ postBody );
119
+ try {
120
+ $ response = Http::retry ($ this ->attempts , 100 )->withBasicAuth ($ this ->config ['username ' ], $ this ->config ['password ' ])
121
+ ->post ($ url , $ postBody );
122
+ } catch (\Exception $ e ) {
123
+ // log the query even on an error
124
+ $ this ->logFMQuery ('post ' , $ url , $ postBody , $ start );
125
+ throw $ e ;
126
+ }
127
+
128
+ // log the query
129
+ $ this ->logFMQuery ('post ' , $ url , $ postBody , $ start );
121
130
122
131
// Check for errors
123
132
$ this ->checkResponseForErrors ($ response );
124
133
125
134
Arr::set ($ postBody , 'fmDataSource.0.username ' , str_repeat ('* ' , strlen (Arr::get ($ postBody , 'fmDataSource.0.username ' ))));
126
135
Arr::set ($ postBody , 'fmDataSource.0.password ' , str_repeat ('* ' , strlen (Arr::get ($ postBody , 'fmDataSource.0.password ' ))));
127
136
128
- $ this ->logFMQuery ('post ' , $ url , $ postBody , $ start );
129
-
130
137
// Get the session token from the response
131
138
$ token = Arr::get ($ response , 'response.token ' );
132
139
@@ -718,7 +725,17 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req
718
725
$ request = $ this ->prepareRequestForSending ($ request );
719
726
720
727
// make the request
721
- $ response = $ request ->{$ method }($ url , $ params );
728
+
729
+ try {
730
+ $ response = $ request ->{$ method }($ url , $ params );
731
+ } catch (\Exception $ e ) {
732
+ // log the query before throwing the exception
733
+ $ this ->logFMQuery ($ method , $ url , $ params , $ start );
734
+ throw $ e ;
735
+ }
736
+ // log the query after a successful request
737
+ $ this ->logFMQuery ($ method , $ url , $ params , $ start );
738
+
722
739
// Check for errors
723
740
try {
724
741
$ this ->checkResponseForErrors ($ response );
@@ -730,19 +747,27 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req
730
747
731
748
// try the request again with refreshed credentials
732
749
$ request = $ this ->prepareRequestForSending ($ request );
733
- $ response = $ request ->{$ method }($ url , $ params );
750
+ try {
751
+ // execute the request
752
+ $ response = $ request ->{$ method }($ url , $ params );
753
+ } catch (\Exception $ e ) {
754
+ // log the query before throwing the exception
755
+ $ this ->logFMQuery ($ method , $ url , $ params , $ start );
756
+ throw $ e ;
757
+ }
758
+
759
+ // log the query after a successful request
760
+ $ this ->logFMQuery ($ method , $ url , $ params , $ start );
734
761
735
- // check for errors a second time, but this time we won't catch the error if there's still an auth
736
- // problem
762
+ // check for errors a second time, but this time we won't catch the error if there's
763
+ // still an auth problem
737
764
$ this ->checkResponseForErrors ($ response );
738
765
739
766
} else {
740
767
throw $ e ;
741
768
}
742
769
}
743
770
744
- $ this ->logFMQuery ($ method , $ url , $ params , $ start );
745
-
746
771
// Return the JSON response
747
772
$ json = $ response ->json ();
748
773
0 commit comments