Skip to content

Commit 0d1ddc8

Browse files
committed
AC-1271: Add rate limiting for payment information endpoint and mutation
1 parent cd82136 commit 0d1ddc8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
2525
use Magento\Framework\GraphQl\Schema\SchemaGeneratorInterface;
2626
use Magento\Framework\Serialize\SerializerInterface;
27+
use Magento\Framework\Webapi\Exception;
2728
use Magento\Framework\Webapi\Response;
2829
use Magento\GraphQl\Helper\Query\Logger\LogData;
30+
use Magento\GraphQl\Model\Backpressure\GraphQlTooManyRequestsException;
2931
use Magento\GraphQl\Model\Query\ContextFactoryInterface;
3032
use Magento\GraphQl\Model\Query\Logger\LoggerPool;
3133

@@ -194,6 +196,19 @@ public function dispatch(RequestInterface $request): ResponseInterface
194196
$this->contextFactory->create(),
195197
$data['variables'] ?? []
196198
);
199+
200+
if (isset($result['errors']) && is_array($result['errors'])) {
201+
foreach ($result['errors'] as $error) {
202+
if (isset($error['extensions']) && is_array($error['extensions'])) {
203+
foreach ($error['extensions'] as $key => $value) {
204+
if (GraphQlTooManyRequestsException::EXCEPTION_CATEGORY === $value
205+
&& 'category' === $key) {
206+
$statusCode = Exception::HTTP_TOO_MANY_REQUESTS;
207+
}
208+
}
209+
}
210+
}
211+
}
197212
} catch (\Exception $error) {
198213
$result['errors'] = isset($result['errors']) ? $result['errors'] : [];
199214
$result['errors'][] = $this->graphQlError->create($error);

0 commit comments

Comments
 (0)