Fix error message when the user tries to update an API Role that has already been assigned to a user. #194

This commit is contained in:
Korina Cordero 2019-05-10 07:08:42 +00:00
parent e22c62ebab
commit 3c9802bbd2
2 changed files with 15 additions and 2 deletions

View file

@ -11,6 +11,7 @@ use Doctrine\ORM\Query;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use App\Menu\Generator as MenuGenerator;
use App\Access\Generator as ACLGenerator;
@ -272,7 +273,19 @@ class APIRoleController extends BaseController
], 422);
} else {
// validated! save the entity
$em->flush();
// catch the exception in case user updated the id
try
{
$em->flush();
}
catch(ForeignKeyConstraintViolationException $e)
{
$error_array['id'] = 'Role has already been assigned to user/s and id cannot be updated';
return $this->json([
'success' => false,
'errors' => $error_array
], 403);
}
// return successful response
return $this->json([

View file

@ -116,7 +116,7 @@
}
});
}).fail(function(response) {
if (response.status == 422) {
if (response.status == 422 || response.status == 403) {
var errors = response.responseJSON.errors;
var firstfield = false;