Add throttle handle
This commit is contained in:
parent
873d57d8c1
commit
d62e3a18e1
2 changed files with 13 additions and 3 deletions
|
|
@ -17,6 +17,7 @@ use Kwaadpepper\Enum\BaseEnum;
|
|||
* @method static self methodNotAllowed()
|
||||
* @method static self wrongTimeStamp()
|
||||
* @method static self arcardiaXmlMailFailed()
|
||||
* @method static self throttleRequestsException()
|
||||
*/
|
||||
class ApiError extends BaseEnum
|
||||
{
|
||||
|
|
@ -34,7 +35,8 @@ class ApiError extends BaseEnum
|
|||
'singleOptinCustomerExists' => 120,
|
||||
'methodNotAllowed' => 150,
|
||||
'wrongTimeStamp' => 151,
|
||||
'arcardiaXmlMailFailed' => 204
|
||||
'arcardiaXmlMailFailed' => 204,
|
||||
'throttleRequestsException' => 429
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +52,8 @@ class ApiError extends BaseEnum
|
|||
'needAuth' => trans('You need to be authenticated'),
|
||||
'methodNotAllowed' => trans('This method is not allowed for this request'),
|
||||
'wrongTimeStamp' => trans('Your request is malformed, please check timestamp header and parameter'),
|
||||
'arcardiaXmlMailFailed' => trans('Arcadia XML Creation failed.')
|
||||
'arcardiaXmlMailFailed' => trans('Arcadia XML Creation failed.'),
|
||||
'throttleRequestsException' => trans('Throttle: too many request have been attempted, please retry later')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use App\Mail\ExceptionAlert;
|
|||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Exceptions\ThrottleRequestsException;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
|
|
@ -83,7 +84,7 @@ class Handler extends ExceptionHandler
|
|||
*/
|
||||
public function render($request, Throwable $e)
|
||||
{
|
||||
if (Helper::isRequestForApiV2($request) and $request->ajax()) {
|
||||
if (Helper::isRequestForApiV2($request) and $request->isJson()) {
|
||||
switch (get_class($e)) {
|
||||
case AuthenticationException::class:
|
||||
/** @var AuthenticationException $e */
|
||||
|
|
@ -119,6 +120,12 @@ class Handler extends ExceptionHandler
|
|||
'message' => $e->getMessage(),
|
||||
'code' => $e->getCode()
|
||||
], $e->getStatusCode());
|
||||
case ThrottleRequestsException::class:
|
||||
/** @var ThrottleRequestsException $e */
|
||||
return response()->json([
|
||||
'message' => ApiError::throttleRequestsException()->label,
|
||||
'code' => ApiError::throttleRequestsException()->value
|
||||
], 429);
|
||||
case CrmException::class:
|
||||
default:
|
||||
return response()->json([
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue