Skip to content

Commit 30b5a18

Browse files
authored
Merge pull request #122 from apisearch-io/feature/too-many-requests-exception
Added too many requests exception. Improved 500 message
2 parents 9eafd40 + d35ea78 commit 30b5a18

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Apisearch PHP Client.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Apisearch\Exception;
17+
18+
/**
19+
* Class TooManyRequestsException
20+
*/
21+
class TooManyRequestsException extends TransportableException
22+
{
23+
/**
24+
* Get http error code.
25+
*
26+
* @return int
27+
*/
28+
public static function getTransportableHTTPError(): int
29+
{
30+
return 429;
31+
}
32+
33+
/**
34+
* Index exists.
35+
*
36+
* @return ResourceExistsException
37+
*/
38+
public static function tooManyRequestsReached(): self
39+
{
40+
return new self('You reached the rate limit. Please, check your permissions');
41+
}
42+
}

Http/HttpResponsesToException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected static function throwTransportableExceptionIfNeeded(
5858
case ForbiddenException::getTransportableHTTPError():
5959
throw new ForbiddenException($response['body']['message']);
6060
case ConnectionException::getTransportableHTTPError():
61-
throw new ConnectionException('Apisearch returned an internal error code [500]');
61+
throw new ConnectionException('Apisearch returned an internal error code [500] - ' . $response['body']['message']);
6262
}
6363
}
6464
}

0 commit comments

Comments
 (0)