Created
July 26, 2023 08:21
-
-
Save sonOfRa/1a06837e3550d592c14197eb1a8cbc3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; | |
import jakarta.annotation.Priority; | |
import jakarta.ws.rs.BadRequestException; | |
import jakarta.ws.rs.core.Response; | |
import jakarta.ws.rs.ext.ExceptionMapper; | |
import jakarta.ws.rs.ext.Provider; | |
import org.keycloak.common.util.Resteasy; | |
import org.keycloak.models.KeycloakSession; | |
import org.keycloak.services.error.KeycloakErrorHandler; | |
@Priority(Integer.MIN_VALUE) | |
@Provider | |
public class CustomUnknownFieldExceptionHandler implements ExceptionMapper<UnrecognizedPropertyException> { | |
@Override | |
public Response toResponse(UnrecognizedPropertyException exception) { | |
return KeycloakErrorHandler.getResponse(Resteasy.getContextData(KeycloakSession.class), new BadRequestException(exception.getMessage())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment