From c48ffc22c846e73fb0623c6ad2cdbec05229aafe Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 1 Aug 2024 14:50:51 +0800 Subject: [PATCH] Throw exception in catch block to ensure that the code execution / flowed stops - This to prevent broken data to be entered into tables --- app/Http/Controllers/BayaranController.php | 4 ++++ app/Services/BillplzService.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/app/Http/Controllers/BayaranController.php b/app/Http/Controllers/BayaranController.php index 6083526..8d23851 100644 --- a/app/Http/Controllers/BayaranController.php +++ b/app/Http/Controllers/BayaranController.php @@ -116,6 +116,8 @@ class BayaranController extends Controller } catch (\Exception $e) { OnlineTransactionLoggerService::logs($bill['id'], $paymentArray, $e->getMessage(), TransactionOnlineStatus::INITIALIZED_TRANSACTION); + + throw $e; } try { @@ -130,6 +132,8 @@ class BayaranController extends Controller } catch (\Exception $e) { OnlineTransactionLoggerService::logs($bill['id'], $paymentArray, $e->getMessage(), TransactionOnlineStatus::UPDATED_TAG_PORTAL); + + throw $e; } return true; diff --git a/app/Services/BillplzService.php b/app/Services/BillplzService.php index 86220ac..98e6f51 100644 --- a/app/Services/BillplzService.php +++ b/app/Services/BillplzService.php @@ -70,6 +70,8 @@ class BillplzService OnlineTransactionLoggerService::logs( null, $composed_data, $e->getMessage(), TransactionOnlineStatus::BILL_CREATED); }; + throw $e; + } } @@ -85,6 +87,8 @@ class BillplzService } catch(\Exception $e){ OnlineTransactionLoggerService::logs($request['billplz']['id'], $request, $e->getMessage(), TransactionOnlineStatus::UPDATE_TRANSACTION_REDIRECT); + + throw $e; } } @@ -99,6 +103,8 @@ class BillplzService } catch (\Exception $e) { OnlineTransactionLoggerService::logs($request['billplz']['id'], $request, $e->getMessage(), TransactionOnlineStatus::UPDATE_TRANSACTION_CALLBACK); + + throw $e; } } @@ -176,6 +182,7 @@ class BillplzService } catch (\Throwable $th) { logger()->error('Error when querying billplz id : ' . $billId); logger()->error($th->getMessage()); + throw $th; } } }