From 497e380c7911d96717ee876a0b1c46f0a3d18ac3 Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Tue, 30 Jul 2024 12:26:04 -0400 Subject: [PATCH 1/3] added more try/catch to make sure we log after each request, even on an error --- src/Services/FileMakerConnection.php | 45 +++++++++++++++++++++------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/Services/FileMakerConnection.php b/src/Services/FileMakerConnection.php index 5b3e627..24316d7 100644 --- a/src/Services/FileMakerConnection.php +++ b/src/Services/FileMakerConnection.php @@ -116,8 +116,17 @@ protected function fetchNewSessionToken() ]; // perform the login - $response = Http::retry($this->attempts, 100)->withBasicAuth($this->config['username'], $this->config['password']) - ->post($url, $postBody); + try { + $response = Http::retry($this->attempts, 100)->withBasicAuth($this->config['username'], $this->config['password']) + ->post($url, $postBody); + } catch (\Exception $e) { + // log the query even on an error + $this->logFMQuery('post', $url, $postBody, $start); + throw $e; + } + + // log the query + $this->logFMQuery('post', $url, $postBody, $start); // Check for errors $this->checkResponseForErrors($response); @@ -125,8 +134,6 @@ protected function fetchNewSessionToken() Arr::set($postBody, 'fmDataSource.0.username', str_repeat('*', strlen(Arr::get($postBody, 'fmDataSource.0.username')))); Arr::set($postBody, 'fmDataSource.0.password', str_repeat('*', strlen(Arr::get($postBody, 'fmDataSource.0.password')))); - $this->logFMQuery('post', $url, $postBody, $start); - // Get the session token from the response $token = Arr::get($response, 'response.token'); @@ -718,7 +725,17 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req $request = $this->prepareRequestForSending($request); // make the request - $response = $request->{$method}($url, $params); + + try { + $response = $request->{$method}($url, $params); + } catch (\Exception $e) { + // log the query before throwing the exception + $this->logFMQuery($method, $url, $params, $start); + throw $e; + } + // log the query after a successful request + $this->logFMQuery($method, $url, $params, $start); + // Check for errors try { $this->checkResponseForErrors($response); @@ -730,10 +747,20 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req // try the request again with refreshed credentials $request = $this->prepareRequestForSending($request); - $response = $request->{$method}($url, $params); + try { + // execute the request + $response = $request->{$method}($url, $params); + } catch (\Exception $e) { + // log the query before throwing the exception + $this->logFMQuery($method, $url, $params, $start); + throw $e; + } + + // log the query after a successful request + $this->logFMQuery($method, $url, $params, $start); - // check for errors a second time, but this time we won't catch the error if there's still an auth - // problem + // check for errors a second time, but this time we won't catch the error if there's + // still an auth problem $this->checkResponseForErrors($response); } else { @@ -741,8 +768,6 @@ protected function makeRequest($method, $url, $params = [], ?PendingRequest $req } } - $this->logFMQuery($method, $url, $params, $start); - // Return the JSON response $json = $response->json(); From 00b67a20d2b1c76e451fcc8008e627f844d4c169 Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Tue, 30 Jul 2024 12:33:45 -0400 Subject: [PATCH 2/3] updated pint and ran formatting --- composer.json | 2 +- src/Database/Eloquent/FMModel.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index d6984f0..215bfe8 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "require-dev": { "orchestra/testbench": "^9.0", "mockery/mockery": "^1.5.1", - "laravel/pint": "^1.1" + "laravel/pint": "^1.17" }, "extra": { "laravel": { diff --git a/src/Database/Eloquent/FMModel.php b/src/Database/Eloquent/FMModel.php index c5f00ca..47644a4 100644 --- a/src/Database/Eloquent/FMModel.php +++ b/src/Database/Eloquent/FMModel.php @@ -150,7 +150,7 @@ public static function createModelsFromRecordSet(BaseCollection $records): Colle // return an empty Eloquent/Collection (or the custom collection specified in the model) if an empty collection was // passed in. if ($records->count() === 0) { - return (new static())->newCollection(); + return (new static)->newCollection(); } // Records passed in weren't empty, so process the records @@ -159,7 +159,7 @@ public static function createModelsFromRecordSet(BaseCollection $records): Colle }); // return the filled Eloquent/Collection (or the custom collection specified in the model) - return (new static())->newCollection($mappedRecords->all()); + return (new static)->newCollection($mappedRecords->all()); } /** Fill in data for this existing model with record data from FileMaker From ad856cd1968f36af5a05fedcd2d522ed02fa03bc Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Tue, 30 Jul 2024 12:36:02 -0400 Subject: [PATCH 3/3] new pint version style changes --- src/Services/FileMakerConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/FileMakerConnection.php b/src/Services/FileMakerConnection.php index 24316d7..5abba49 100644 --- a/src/Services/FileMakerConnection.php +++ b/src/Services/FileMakerConnection.php @@ -834,7 +834,7 @@ public function setRetries($retries) protected function getDefaultQueryGrammar() { - return new FMGrammar(); + return new FMGrammar; } // public function getLayoutMetadata($layout = null)