Skip to content

Commit 6310812

Browse files
authored
Merge pull request #304 from EasyPost/bad_request_exception
feat: maps 400 status codes to BadRequestException class
2 parents 3818275 + 78786c8 commit 6310812

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next Release
44

55
- Adds new `RequestHook` and `ResponseHook` events. (un)subscribe to them with the new `subscribeToRequestHook`, `subscribeToResponseHook`, `unsubscribeFromRequestHook`, or `unsubscribeFromResponseHook` methods of an `EasyPostClient`
6+
- Maps 400 status codes to new `BadRequestException` class
67

78
## v6.7.0 (2023-06-06)
89

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace EasyPost\Exception\Api;
4+
5+
class BadRequestException extends ApiException
6+
{
7+
}

lib/EasyPost/Http/Requestor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use EasyPost\Constant\Constants;
88
use EasyPost\EasyPostClient;
99
use EasyPost\EasypostObject;
10+
use EasyPost\Exception\Api\BadRequestException;
1011
use EasyPost\Exception\Api\ForbiddenException;
1112
use EasyPost\Exception\Api\GatewayTimeoutException;
1213
use EasyPost\Exception\Api\HttpException;
@@ -272,6 +273,7 @@ public static function interpretResponse($httpBody, $httpStatus)
272273
* @param string $httpBody
273274
* @param int $httpStatus
274275
* @param array $response
276+
* @throws BadRequestException
275277
* @throws GatewayTimeoutException
276278
* @throws InternalServerException
277279
* @throws InvalidRequestException
@@ -306,6 +308,9 @@ public static function handleApiError($httpBody, $httpStatus, $response)
306308
}
307309

308310
switch ($httpStatus) {
311+
case 400:
312+
$errorType = BadRequestException::class;
313+
break;
309314
case 401:
310315
$errorType = UnauthorizedException::class;
311316
break;

lib/easypost.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
// API Exceptions
1515
require_once(dirname(__FILE__) . '/EasyPost/Exception/Api/ApiException.php');
16+
require_once(dirname(__FILE__) . '/EasyPost/Exception/Api/BadRequestException.php');
1617
require_once(dirname(__FILE__) . '/EasyPost/Exception/Api/EncodingException.php');
1718
require_once(dirname(__FILE__) . '/EasyPost/Exception/Api/ExternalApiException.php');
1819
require_once(dirname(__FILE__) . '/EasyPost/Exception/Api/ForbiddenException.php');

0 commit comments

Comments
 (0)