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".' );