diff --git a/areas/users/user_service.py b/areas/users/user_service.py index c75185d..0d8c4e3 100644 --- a/areas/users/user_service.py +++ b/areas/users/user_service.py @@ -1,11 +1,7 @@ -import copy -from areas.apps.models import App - from database import db -from areas.apps import AppRole +from areas.apps.models import App, AppRole from helpers import KratosApi - class UserService: @staticmethod def get_users(): @@ -75,9 +71,12 @@ class UserService: @staticmethod def delete_user(id): app_role = AppRole.query.filter_by(user_id=id).all() - for ar in app_role: - db.session.delete(ar) - db.session.commit() + try: + for ar in app_role: + db.session.delete(ar) + db.session.commit() + except: + raise Exception('Exception during user roles deletion for userId: {}').__format__(id) @staticmethod def __insertAppRoleToUser(userId, userRes): diff --git a/areas/users/users.py b/areas/users/users.py index 90bc113..65f0ca1 100644 --- a/areas/users/users.py +++ b/areas/users/users.py @@ -50,8 +50,11 @@ def put_user(id): @jwt_required() @cross_origin() def delete_user(id): - res = KratosApi.delete("/identities/{}".format(id)) - UserService.delete_user(id) - if res.status_code == 204: - return jsonify(), res.status_code - return jsonify(res.json()), res.status_code + try: + res = KratosApi.delete("/identities/{}".format(id)) + if res.status_code == 204: + UserService.delete_user(id) + return jsonify(), res.status_code + return jsonify(res.json()), res.status_code + except: + return jsonify({"message":"There was an error deleting user"}), 404