Skip to content

Commit 8bbf53a

Browse files
feat!: rename errors to exceptions
1 parent 06fee57 commit 8bbf53a

25 files changed

+114
-114
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ foreach ($page->pagingEachItem() as $item) {
110110

111111
### Handling errors
112112

113-
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Anthropic\Errors\APIError` will be thrown:
113+
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Anthropic\Core\Exceptions\APIException` will be thrown:
114114

115115
```php
116116
<?php
117117

118-
use Anthropic\Core\Errors\APIConnectionError;
118+
use Anthropic\Core\Exceptions\APIConnectionException;
119119
use Anthropic\Messages\MessageParam;
120120

121121
try {
@@ -124,7 +124,7 @@ try {
124124
messages: [MessageParam::with(role: "user", content: "Hello, Claude")],
125125
model: "claude-sonnet-4-20250514",
126126
);
127-
} catch (APIConnectionError $e) {
127+
} catch (APIConnectionException $e) {
128128
echo "The server could not be reached", PHP_EOL;
129129
var_dump($e->getPrevious());
130130
} catch (RateLimitError $_) {
@@ -137,19 +137,19 @@ try {
137137

138138
Error codes are as follows:
139139

140-
| Cause | Error Type |
141-
| ---------------- | -------------------------- |
142-
| HTTP 400 | `BadRequestError` |
143-
| HTTP 401 | `AuthenticationError` |
144-
| HTTP 403 | `PermissionDeniedError` |
145-
| HTTP 404 | `NotFoundError` |
146-
| HTTP 409 | `ConflictError` |
147-
| HTTP 422 | `UnprocessableEntityError` |
148-
| HTTP 429 | `RateLimitError` |
149-
| HTTP >= 500 | `InternalServerError` |
150-
| Other HTTP error | `APIStatusError` |
151-
| Timeout | `APITimeoutError` |
152-
| Network error | `APIConnectionError` |
140+
| Cause | Error Type |
141+
| ---------------- | ------------------------------ |
142+
| HTTP 400 | `BadRequestException` |
143+
| HTTP 401 | `AuthenticationException` |
144+
| HTTP 403 | `PermissionDeniedException` |
145+
| HTTP 404 | `NotFoundException` |
146+
| HTTP 409 | `ConflictException` |
147+
| HTTP 422 | `UnprocessableEntityException` |
148+
| HTTP 429 | `RateLimitException` |
149+
| HTTP >= 500 | `InternalServerException` |
150+
| Other HTTP error | `APIStatusException` |
151+
| Timeout | `APITimeoutException` |
152+
| Network error | `APIConnectionException` |
153153

154154
### Retries
155155

src/Core/BaseClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Anthropic\Core\Contracts\BaseStream;
99
use Anthropic\Core\Conversion\Contracts\Converter;
1010
use Anthropic\Core\Conversion\Contracts\ConverterSource;
11-
use Anthropic\Core\Errors\APIStatusError;
11+
use Anthropic\Core\Exceptions\APIStatusException;
1212
use Anthropic\RequestOptions;
1313
use Http\Discovery\Psr17FactoryDiscovery;
1414
use Http\Discovery\Psr18ClientDiscovery;
@@ -203,7 +203,7 @@ protected function sendRequest(
203203
}
204204

205205
if ($code >= 400 && $code < 500) {
206-
throw APIStatusError::from(request: $req, response: $rsp);
206+
throw APIStatusException::from(request: $req, response: $rsp);
207207
}
208208

209209
if ($code >= 500 && $retryCount < $opts->maxRetries) {

src/Core/Concerns/SdkPage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Anthropic\Client;
88
use Anthropic\Core\Conversion\Contracts\Converter;
99
use Anthropic\Core\Conversion\Contracts\ConverterSource;
10-
use Anthropic\Core\Errors\APIStatusError;
10+
use Anthropic\Core\Exceptions\APIStatusException;
1111
use Anthropic\RequestOptions;
1212

1313
/**
@@ -52,7 +52,7 @@ public function hasNextPage(): bool
5252
*
5353
* @return static of static<Item>
5454
*
55-
* @throws APIStatusError
55+
* @throws APIStatusException
5656
*/
5757
public function getNextPage(): static
5858
{

src/Core/Errors/AuthenticationError.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Core/Errors/BadRequestError.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Core/Errors/ConflictError.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Core/Errors/InternalServerError.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Core/Errors/NotFoundError.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Core/Errors/PermissionDeniedError.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Core/Errors/RateLimitError.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)