<!-- <https://mvnrepository.com/artifact/org.keycloak/keycloak-admin-client> -->
		<dependency>
		<!-- The Keycloak Admin API client for e.g. creating Users and Roles through code in Java,
			Date:  Jan 17, 2025-->
			<groupId>org.keycloak</groupId>
			<artifactId>keycloak-admin-client</artifactId>
			<version>26.0.4</version>
		</dependency>

🔧 Keycloak Admin Client – Exception Handling Table

Exception Type When It Occurs Typical Scenarios Handling Recommendations
javax.ws.rs.WebApplicationException When a REST call fails with a non-2xx response 404 Not Found, 409 Conflict, 401 Unauthorized, 400 Bad Request Log getStatus() and readEntity(String.class) to inspect error
javax.ws.rs.ProcessingException Client-side failure during request processing Network timeouts, DNS issues, TLS handshake problems Use retry logic with backoff; check network and server health
java.net.SocketTimeoutException, ConnectException Network-level communication errors Keycloak server down, host unreachable, misconfigured URL Ensure server is reachable and retry on failure
javax.ws.rs.ClientErrorException Subclass of WebApplicationException for 4xx codes 400, 401, 403 due to invalid input or permissions Validate request payloads, check tokens and role scopes
javax.ws.rs.ServerErrorException Subclass of WebApplicationException for 5xx errors Keycloak server-side failures or load issues Check Keycloak logs, retry later, report critical errors
org.keycloak.representations.idm.error.ErrorRepresentation Error response object, not an exception Returned for user/role creation failures or invalid states Deserialize and inspect error, errorMessage, and status
javax.ws.rs.InternalServerErrorException HTTP 500 errors from Keycloak Plugin crashes, unexpected NPEs in Keycloak Analyze logs and check Keycloak health/configuration

Let me know if you’d like a code snippet that wraps these exceptions in a reusable error handler.

✅ Common HTTP Status Codes & Typical Uses

Status Code Meaning Typical Spring Exception / Use Case
400 Bad Request Validation errors, missing parameters, MethodArgumentNotValidException, etc.
401 Unauthorized No authentication or invalid credentials (AuthenticationException)
403 Forbidden Authenticated but not allowed (AccessDeniedException)
404 Not Found Resource not found (EntityNotFoundException, NoHandlerFoundException)
409 Conflict Resource conflict, e.g. duplicate keys, already existing user (DataIntegrityViolationException, custom ConflictException)
422 Unprocessable Entity (sometimes) Semantic errors, e.g. valid syntax but invalid data
500 Internal Server Error Unhandled exceptions, null pointers, etc.

javax.ws.rs.ProcessingException

javax.ws.rs.WebApplicationException

Exception Architecture