Fix the error message when user tries to update the role ID. #210
This commit is contained in:
parent
ce520ebf51
commit
0d291b037c
2 changed files with 16 additions and 2 deletions
|
|
@ -9,6 +9,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;
|
||||
|
|
@ -275,7 +276,19 @@ class RoleController 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([
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@
|
|||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
console.log(response.status);
|
||||
if (response.status == 422 || response.status == 403) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue