Class WebApplicationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
javax.ws.rs.WebApplicationException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ClientErrorException, RedirectionException, ServerErrorException
When is WebApplicationException being thrown?
Throwable
└── RuntimeException
└── WebApplicationException
├── ClientErrorException (for 4xx)
│ ├── BadRequestException (400)
│ ├── NotAuthorizedException (401)
│ ├── ForbiddenException (403)
│ └── NotFoundException (404)
└── ServerErrorException (for 5xx)
├── InternalServerErrorException (500)
├── ServiceUnavailableException (503)
WebApplicationException
— What It CatchesThrown by the Keycloak Admin Client when Keycloak returns an HTTP error (non-2xx) response.
Category | Status Codes | Common Causes |
---|---|---|
Client errors (4xx ) |
400 – Bad Request401 – Unauthorized403 – Forbidden404 – Not Found409 – Conflict | Invalid input, missing/expired token, no permission, not found, user already exists |
Server errors (5xx ) |
500 – Internal Server Error503 – Service Unavailable | Keycloak server crash, overload, config issues |
e.getResponse()
e.getResponse().getStatus()
e.getResponse().readEntity(String.class)
Response
manuallytry {
userResource.get("user-id").toRepresentation(); // throws if 404, 403, etc.
} catch (WebApplicationException e) {
int status = e.getResponse().getStatus();
String body = e.getResponse().readEntity(String.class);
log.error("Keycloak error {}: {}", status, body);
}