From e0b2dc043a793c2a65ffbee3bf263082a0f6adab Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 2 Mar 2023 11:13:56 -0600 Subject: [PATCH] Adds try/catch to users API --- app/Http/Controllers/Api/UsersController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 734125ff34..17a3abdb4c 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -452,10 +452,18 @@ class UsersController extends Controller // Check if the request has groups passed and has a value if ($request->filled('groups')) { - $user->groups()->sync($request->input('groups')); + try{ + $user->groups()->sync($request->input('groups')); + } catch (\Exception $exception){ + return response()->json(Helper::formatStandardApiResponse('error', null, $exception)); + } // The groups field has been passed but it is null, so we should blank it out } elseif ($request->has('groups')) { - $user->groups()->sync([]); + try{ + $user->groups()->sync([]); + } catch (\Exception $exception){ + return response()->json(Helper::formatStandardApiResponse('error', null, $exception)); + } }