Skip to content

Commit 509f94b

Browse files
authored
Handle Webapi Response exception
1 parent 551403e commit 509f94b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Plugin/FrontControllerDispatch.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Opengento\WebapiLogger\Plugin;
1010

1111
use Magento\Framework\App\FrontControllerInterface;
12+
use Magento\Framework\Webapi\Response as WebapiResponse;
1213
use Magento\Framework\App\RequestInterface;
1314
use Magento\Framework\Stdlib\DateTime\DateTime;
1415
use Magento\Webapi\Controller\Rest;
@@ -42,9 +43,8 @@ public function beforeDispatch(FrontControllerInterface $subject, RequestInterfa
4243
public function afterDispatch(FrontControllerInterface $subject, $result, RequestInterface $request): mixed
4344
{
4445
if ($this->config->isEnabled() && !$request->isXmlHttpRequest()) {
45-
$exceptions = $result->getException();
46-
47-
if (!empty($exceptions)) {
46+
$exceptions = $result instanceof WebapiResponse::class ? $result->getException() : '';
47+
if ($exceptions !== []) {
4848
$responseCode = '';
4949
$responseBody = '';
5050
foreach ($exceptions as $exception) {
@@ -55,8 +55,7 @@ public function afterDispatch(FrontControllerInterface $subject, $result, Reques
5555
$responseBody = rtrim($responseBody);
5656
} else {
5757
$responseCode = (string)$result->getStatusCode();
58-
$responseBody = $result->getContent();
59-
$responseBody = trim($responseBody, '"');
58+
$responseBody = trim($result->getContent(), '"');
6059
}
6160

6261
$this->logHandle->after($responseCode, $responseBody, $this->date->gmtDate());

0 commit comments

Comments
 (0)