@@ -116,17 +116,24 @@ protected function fetchNewSessionToken()
116116 ];
117117
118118 // 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 );
121130
122131 // Check for errors
123132 $ this ->checkResponseForErrors ($ response );
124133
125134 Arr::set ($ postBody , 'fmDataSource.0.username ' , str_repeat ('* ' , strlen (Arr::get ($ postBody , 'fmDataSource.0.username ' ))));
126135 Arr::set ($ postBody , 'fmDataSource.0.password ' , str_repeat ('* ' , strlen (Arr::get ($ postBody , 'fmDataSource.0.password ' ))));
127136
128- $ this ->logFMQuery ('post ' , $ url , $ postBody , $ start );
129-
130137 // Get the session token from the response
131138 $ token = Arr::get ($ response , 'response.token ' );
132139
@@ -718,7 +725,17 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req
718725 $ request = $ this ->prepareRequestForSending ($ request );
719726
720727 // 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+
722739 // Check for errors
723740 try {
724741 $ this ->checkResponseForErrors ($ response );
@@ -730,19 +747,27 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req
730747
731748 // try the request again with refreshed credentials
732749 $ 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 );
734761
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
737764 $ this ->checkResponseForErrors ($ response );
738765
739766 } else {
740767 throw $ e ;
741768 }
742769 }
743770
744- $ this ->logFMQuery ($ method , $ url , $ params , $ start );
745-
746771 // Return the JSON response
747772 $ json = $ response ->json ();
748773
@@ -809,7 +834,7 @@ public function setRetries($retries)
809834
810835 protected function getDefaultQueryGrammar ()
811836 {
812- return new FMGrammar () ;
837+ return new FMGrammar ;
813838 }
814839
815840 // public function getLayoutMetadata($layout = null)
0 commit comments