Skip to content

Commit

Permalink
Convert other errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed committed Sep 25, 2024
1 parent cca3d24 commit 21690a1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,12 @@ public function __construct(
if ($secretKey === null) {
$env = getenv('SNAPAUTH_SECRET_KEY');
if ($env === false) {
throw new ApiError(
'Secret key missing. It can be explictly provided, or it ' .
'can be auto-detected from the SNAPAUTH_SECRET_KEY ' .
'environment variable.',
);
throw new Exception\MissingSecretKey();

Check warning on line 56 in src/Client.php

View check run for this annotation

Codecov / codecov/patch

src/Client.php#L56

Added line #L56 was not covered by tests
}
$secretKey = $env;
}
if (!str_starts_with($secretKey, 'secret_')) {
throw new ApiError(
'Invalid secret key. Please verify you copied the full value from the SnapAuth dashboard.',
);
throw new Exception\InvalidSecretKey();

Check warning on line 61 in src/Client.php

View check run for this annotation

Codecov / codecov/patch

src/Client.php#L61

Added line #L61 was not covered by tests
}

$this->secretKey = $secretKey;
Expand Down
18 changes: 18 additions & 0 deletions src/Exception/InvalidSecretKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace SnapAuth\Exception;

use InvalidArgumentException;
use SnapAuth\ApiError;

class InvalidSecretKey extends InvalidArgumentException implements ApiError
{
public function __construct()

Check warning on line 12 in src/Exception/InvalidSecretKey.php

View check run for this annotation

Codecov / codecov/patch

src/Exception/InvalidSecretKey.php#L12

Added line #L12 was not covered by tests
{
parent::__construct(
message: 'Invalid secret key. Please verify you copied the full value from the SnapAuth dashboard.',

Check warning on line 15 in src/Exception/InvalidSecretKey.php

View check run for this annotation

Codecov / codecov/patch

src/Exception/InvalidSecretKey.php#L14-L15

Added lines #L14 - L15 were not covered by tests
);
}
}
19 changes: 19 additions & 0 deletions src/Exception/MissingSecretKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace SnapAuth\Exception;

use InvalidArgumentException;
use SnapAuth\ApiError;

class MissingSecretKey extends InvalidArgumentException implements ApiError
{
public function __construct()

Check warning on line 12 in src/Exception/MissingSecretKey.php

View check run for this annotation

Codecov / codecov/patch

src/Exception/MissingSecretKey.php#L12

Added line #L12 was not covered by tests
{
parent::__construct(
'Secret key missing. It can be explictly provided, or it can be ' .
'auto-detected from the SNAPAUTH_SECRET_KEY environment variable.'

Check warning on line 16 in src/Exception/MissingSecretKey.php

View check run for this annotation

Codecov / codecov/patch

src/Exception/MissingSecretKey.php#L14-L16

Added lines #L14 - L16 were not covered by tests
);
}
}

0 comments on commit 21690a1

Please sign in to comment.