Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit 81b0c1b

Browse files
committed
Add new exceptions
1 parent f90c8ef commit 81b0c1b

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Reflex\Smite\Exceptions;
4+
5+
use Reflex\Smite\ApiException;
6+
7+
class AccessValidationException extends ApiException {
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Reflex\Smite\Exceptions;
4+
5+
use Reflex\Smite\ApiException;
6+
7+
class NotFoundException extends ApiException {
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Reflex\Smite\Exceptions;
4+
5+
use Reflex\Smite\ApiException;
6+
7+
class RateLimitException extends ApiException {
8+
9+
}

src/Request.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
use GuzzleHttp\Client;
1010
use GuzzleHttp\Exception\TransferException;
11+
use Reflex\Smite\Exceptions\AccessValidationException;
12+
use Reflex\Smite\Exceptions\NotFoundException;
13+
use Reflex\Smite\Exceptions\RateLimitException;
1114

1215
/**
1316
* Class to manage individual requests to the Smite API
@@ -257,7 +260,17 @@ public function send() {
257260
try {
258261
$result = $this->api->getGuzzleClient()->get($this->url);
259262
} catch (TransferException $e) {
260-
throw new ApiException($e->getMessage(), $e->getCode(), $e);
263+
$message = $e->getMessage();
264+
265+
if (strpos($message, 'dailylimit') !== false) {
266+
throw new RateLimitException($message, $e->getCode(), $e);
267+
} elseif (strpos($message, 'Exception while validating developer access') !== false) {
268+
throw new AccessValidationException($message, $e->getCode(), $e);
269+
} elseif (strpos($message, '404 Not Found') !== false) {
270+
throw new NotFoundException($message, $e->getCode(), $e);
271+
} else {
272+
throw new ApiException($message, $e->getCode(), $e);
273+
}
261274
}
262275
if ($result->getStatusCode() != 200) {
263276
$respCode = $result->getStatusCode();

0 commit comments

Comments
 (0)