Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/API/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/Exceptions/SigmaAuthenticationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace InterWorks\SigmaREST\Exceptions;

use Exception;

class SigmaAuthenticationException extends Exception
{
public function __construct(string $message = "Sigma authentication failed", int $code = 0, ?Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/SigmaConfigurationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace InterWorks\SigmaREST\Exceptions;

use Exception;

class SigmaConfigurationException extends Exception
{
public function __construct(string $message = "Sigma configuration is invalid or missing", int $code = 0, ?Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
3 changes: 2 additions & 1 deletion src/SigmaREST.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use InterWorks\SigmaREST\API\UserAttributes;
use InterWorks\SigmaREST\API\Workbooks;
use InterWorks\SigmaREST\API\Workspaces;
use InterWorks\SigmaREST\Exceptions\SigmaConfigurationException;

class SigmaREST
{
Expand Down Expand Up @@ -74,7 +75,7 @@ public function __construct(bool $returnResponseObject = false)

// Validate that the URL is set
if (empty($this->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".'
);
Expand Down