From d2a8db28613c1254478d38ac9839a6a31c338a7d Mon Sep 17 00:00:00 2001 From: Justin Lyons Date: Fri, 20 Jun 2025 11:18:02 -0500 Subject: [PATCH] Added custom exceptions --- src/API/Authentication.php | 6 ++++-- src/Exceptions/SigmaAuthenticationException.php | 13 +++++++++++++ src/Exceptions/SigmaConfigurationException.php | 13 +++++++++++++ src/SigmaREST.php | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/Exceptions/SigmaAuthenticationException.php create mode 100644 src/Exceptions/SigmaConfigurationException.php diff --git a/src/API/Authentication.php b/src/API/Authentication.php index 5a61ea0..0dc406c 100644 --- a/src/API/Authentication.php +++ b/src/API/Authentication.php @@ -3,6 +3,8 @@ namespace InterWorks\SigmaREST\API; use Illuminate\Http\Client\Response; +use InterWorks\SigmaREST\Exceptions\SigmaAuthenticationException; +use InterWorks\SigmaREST\Exceptions\SigmaConfigurationException; trait Authentication { @@ -19,7 +21,7 @@ public function getAccessToken(): mixed $clientID = gettype(config('sigmarest.client-id')) == 'string' ? config('sigmarest.client-id') : ''; $clientSecret = gettype(config('sigmarest.client-secret')) == 'string' ? config('sigmarest.client-secret') : ''; if (empty($clientID) || empty($clientSecret)) { - throw new \Exception( + throw new SigmaConfigurationException( 'Client ID (SIGMA_CLIENT_ID) and secret (SIGMA_CLIENT_SECRET) are not set in env file.' . ' If you don\'t have these values, check out this doc: ' . 'https://help.sigmacomputing.com/reference/generate-client-credentials' @@ -55,7 +57,7 @@ public function getAccessToken(): mixed // Check if the token is present if (!isset($responseArr['access_token'])) { - throw new \Exception('Access token not found in response: ' . $response->body()); + throw new SigmaAuthenticationException('Access token not found in response: ' . $response->body()); } // Return the access token diff --git a/src/Exceptions/SigmaAuthenticationException.php b/src/Exceptions/SigmaAuthenticationException.php new file mode 100644 index 0000000..6ad60a6 --- /dev/null +++ b/src/Exceptions/SigmaAuthenticationException.php @@ -0,0 +1,13 @@ +url)) { - throw new \Exception( + throw new SigmaConfigurationException( 'The Sigma URL (SIGMA_API_URL) is not set in the env file.' . ' Find this in the Sigma application > Administration > Site labeled "Cloud".' );