give more useful failure message when event.error is called without first setting event.type

This commit is contained in:
Josh Cain 2018-02-07 16:04:36 -06:00 committed by Marek Posolda
parent 75f040f38e
commit 04c2ad9430

View file

@ -29,6 +29,7 @@ import org.keycloak.models.UserSessionModel;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a> * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
@ -157,6 +158,10 @@ public class EventBuilder {
} }
public void error(String error) { public void error(String error) {
if (Objects.isNull(event.getType())) {
throw new IllegalStateException("Attempted to define event error without first setting the event type");
}
if (!event.getType().name().endsWith("_ERROR")) { if (!event.getType().name().endsWith("_ERROR")) {
event.setType(EventType.valueOf(event.getType().name() + "_ERROR")); event.setType(EventType.valueOf(event.getType().name() + "_ERROR"));
} }