From fdb6970f36456c3b85ad3e7dcdeb824a8c935280 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 23 Oct 2024 01:41:27 -0500 Subject: [PATCH] this is pretty much done --- .../CheckoutRequests/CreateCheckoutRequest.php | 12 +++--------- app/Http/Controllers/Api/CheckoutRequest.php | 9 +++++++-- app/Http/Controllers/ViewAssetsController.php | 9 +++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/Actions/CheckoutRequests/CreateCheckoutRequest.php b/app/Actions/CheckoutRequests/CreateCheckoutRequest.php index c90ca4f23c..9d1ba332ff 100644 --- a/app/Actions/CheckoutRequests/CreateCheckoutRequest.php +++ b/app/Actions/CheckoutRequests/CreateCheckoutRequest.php @@ -12,6 +12,7 @@ use App\Models\User; use App\Notifications\RequestAssetCancelation; use App\Notifications\RequestAssetNotification; use Illuminate\Auth\Access\AuthorizationException; +use Log; class CreateCheckoutRequest { @@ -47,16 +48,9 @@ class CreateCheckoutRequest try { $settings->notify(new RequestAssetNotification($data)); } catch (\Exception $e) { - \Log::warning($e); + Log::warning($e); } - return true; // or $asset, or whatever + return true; } - - public function doSomethingElse() - { - - } - - } \ No newline at end of file diff --git a/app/Http/Controllers/Api/CheckoutRequest.php b/app/Http/Controllers/Api/CheckoutRequest.php index 3b31451376..1ee9c4c025 100644 --- a/app/Http/Controllers/Api/CheckoutRequest.php +++ b/app/Http/Controllers/Api/CheckoutRequest.php @@ -30,7 +30,12 @@ class CheckoutRequest extends Controller public function destroy(Asset $asset): JsonResponse { - CancelCheckoutRequest::run($asset, auth()->user()); - return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.requests.canceled'))); + try { + CancelCheckoutRequest::run($asset, auth()->user()); + return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.requests.canceled'))); + } catch (\Exception $e) { + report($e); + return response()->json(Helper::formatStandardApiResponse('error', null, $e->getMessage())); + } } } diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 83a2168311..56d1f8b390 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -164,8 +164,13 @@ class ViewAssetsController extends Controller public function destroy(Asset $asset): RedirectResponse { - CancelCheckoutRequest::run($asset, auth()->user()); - return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled')); + try { + CancelCheckoutRequest::run($asset, auth()->user()); + return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled')); + } catch (\Exception $e) { + report($e); + return redirect()->back()->with('error', 'something bad happened'); + } }