Merge pull request #2810 from thomasdarimont/issue/KEYCLOAK-2974-handle-ModelException-in-UsersResource

KEYCLOAK-2974: Handle ModelException in UsersResource
This commit is contained in:
Bill Burke 2016-06-05 11:06:32 -04:00
commit b3f3449e39

View file

@ -184,6 +184,8 @@ public class UsersResource {
return ErrorResponse.exists("User exists with same username or email"); return ErrorResponse.exists("User exists with same username or email");
} catch (ModelReadOnlyException re) { } catch (ModelReadOnlyException re) {
return ErrorResponse.exists("User is read only!"); return ErrorResponse.exists("User is read only!");
} catch (ModelException me) {
return ErrorResponse.exists("Could not update user!");
} }
} }
@ -226,6 +228,11 @@ public class UsersResource {
session.getTransaction().setRollbackOnly(); session.getTransaction().setRollbackOnly();
} }
return ErrorResponse.exists("User exists with same username or email"); return ErrorResponse.exists("User exists with same username or email");
} catch (ModelException me){
if (session.getTransaction().isActive()) {
session.getTransaction().setRollbackOnly();
}
return ErrorResponse.exists("Could not create user");
} }
} }