Adds try/catch to users API

This commit is contained in:
Ivan Nieto Vivanco 2023-03-02 11:13:56 -06:00
parent 78b36c7886
commit e0b2dc043a

View file

@ -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));
}
}