Skip to content

Commit e3088fe

Browse files
atuld123Atul Dusane
andauthored
fixed error message for refund, shipped and cancel order (#247)
* fixed error message for refund, shipped and cancel order * updated code as per code review comments * fixed error message for refund, shipped and cancel order * updated code as per code review comments * fixed static code warnings * fixed static code warnings --------- Co-authored-by: Atul Dusane <[email protected]>
1 parent 25e8826 commit e3088fe

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

app/code/Meta/Sales/Observer/Order/Cancel.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace Meta\Sales\Observer\Order;
1919

20+
use Exception;
2021
use GuzzleHttp\Exception\GuzzleException;
2122
use Magento\Framework\Event\Observer;
2223
use Magento\Framework\Event\ObserverInterface;
@@ -86,13 +87,22 @@ public function execute(Observer $observer)
8687
* @param string $fbOrderId
8788
* @return void
8889
* @throws GuzzleException
90+
* @throws Exception
8991
*/
9092
private function cancelOrder(int $storeId, string $fbOrderId)
9193
{
9294
$this->graphAPIAdapter
9395
->setDebugMode($this->systemConfig->isDebugMode($storeId))
9496
->setAccessToken($this->systemConfig->getAccessToken($storeId));
95-
96-
$this->graphAPIAdapter->cancelOrder($fbOrderId);
97+
try {
98+
$this->graphAPIAdapter->cancelOrder($fbOrderId);
99+
} catch (GuzzleException $e) {
100+
$response = $e->getResponse();
101+
$body = json_decode($response->getBody());
102+
throw new Exception('Error Code: '
103+
.(string) $body->error->code
104+
.'; '
105+
. (string) $body->error->error_user_msg);
106+
}
97107
}
98108
}

app/code/Meta/Sales/Observer/Order/MarkAsShipped.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace Meta\Sales\Observer\Order;
1919

20+
use Exception;
2021
use Meta\Sales\Model\Order\Shipper;
2122
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
2223
use GuzzleHttp\Exception\GuzzleException;
@@ -64,6 +65,7 @@ public function __construct(
6465
* @param Observer $observer
6566
* @throws LocalizedException
6667
* @throws GuzzleException
68+
* @throws Exception
6769
*/
6870
public function execute(Observer $observer)
6971
{
@@ -88,7 +90,15 @@ public function execute(Observer $observer)
8890
&& $this->systemConfig->isOnsiteCheckoutEnabled($storeId))) {
8991
return;
9092
}
91-
92-
$this->shipper->markAsShipped($shipment);
93+
try {
94+
$this->shipper->markAsShipped($shipment);
95+
} catch (GuzzleException $e) {
96+
$response = $e->getResponse();
97+
$body = json_decode($response->getBody());
98+
throw new Exception('Error Code: '
99+
.(string) $body->error->code
100+
.'; '
101+
. (string) $body->error->error_user_msg);
102+
}
93103
}
94104
}

app/code/Meta/Sales/Observer/Order/Refund.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function execute(Observer $observer)
146146
* @param string|null $currencyCode
147147
* @param string|null $reasonText
148148
* @throws GuzzleException
149+
* @throws Exception
149150
*/
150151
private function refundOrder(
151152
int $storeId,
@@ -159,13 +160,22 @@ private function refundOrder(
159160
->setDebugMode($this->systemConfig->isDebugMode($storeId))
160161
->setAccessToken($this->systemConfig->getAccessToken($storeId));
161162

162-
$this->graphAPIAdapter->refundOrder(
163-
$fbOrderId,
164-
$items,
165-
$shippingRefundAmount,
166-
$currencyCode,
167-
$reasonText
168-
);
163+
try {
164+
$this->graphAPIAdapter->refundOrder(
165+
$fbOrderId,
166+
$items,
167+
$shippingRefundAmount,
168+
$currencyCode,
169+
$reasonText
170+
);
171+
} catch (GuzzleException $e) {
172+
$response = $e->getResponse();
173+
$body = json_decode($response->getBody());
174+
throw new Exception('Error Code: '
175+
.(string) $body->error->code
176+
.'; '
177+
. (string) $body->error->error_user_msg);
178+
}
169179
}
170180

171181
/**

0 commit comments

Comments
 (0)