Java Admin Client: is there a class to deserialize error response?

216 views
Skip to first unread message

Thomas LIMIN

unread,
Feb 3, 2021, 5:15:49 AM2/3/21
to Keycloak User

Hello
I'm using the java admin client (org.keycloak.admin.client.Keycloak) to create new keycloak users.

Sometimes user creation failed, so I try to retrieve the response entity. Which java class  can I use to deserialize the actual json response body content? I'm currently simply using String.class, is there a specific keycloak "error message" class?

        // create keycloak user
        try (final Response userCreationResponse = this.keycloakUsersResource.create(keycloakUser)) {
            try {
                keycloakUserId = CreatedResponseUtil.getCreatedId(userCreationResponse);
            } catch (final WebApplicationException e) {
                final String responseBody = userCreationResponse.readEntity(String.class);
                log.error("error during keycloak user creation: {}, {}", e.getMessage(), responseBody, e);
                throw e;
            }
        }

Some example of retrieved strings:
{"error":"unknown_error"}  ,  with HTTP 500 status
{"errorMessage":"User exists with same username"} , with HTTP 409 status


Regards

Thomas LIMIN
Reply all
Reply to author
Forward
0 new messages