简体   繁体   中英

Keycloak custom exception in User Storage SPI

We have our own implementation of UserStorageProvider and UserRegistrationProvider. In addUser I want to throw custom exception

@Override
public UserModel addUser(RealmModel realmModel, String s) {
  throw new CustomException("Custom exception");
}

But how to handle it from client side? I always getting 500 Internal Server Error with

{"error":"unknown_error"}

response in it. I want to see another status code and error message. How to achieve such behavior? Thanks.

You can try extending one of Keycloak's Exception classes.

For example using org.keycloak.services.ErrorResponseException you can define (String error, String errorDescription, Response.Status status) in the constructor.

You can also check all Exceptions that extend javax.ws.rs.WebApplicationException, maybe you will find more suitable example for your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM