Skip to content

A free open source IT asset/license management system

Adds try/catch to users API

Ivan Nieto Vivancoe0b2dc043a79
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));
+ }
}