Skip to content

Commit

Permalink
Register NoSuchElementExceptionMapper in StandardExceptionMappers
Browse files Browse the repository at this point in the history
This makes NoSuchElementExceptionMapper one of our "standard"
exception mappers. This is unique to kiwi and does not
replace an existing Dropwizard exception mapper.

Closes #424
  • Loading branch information
sleberknight committed Jan 7, 2024
1 parent e706242 commit c92fd74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.kiwiproject.jaxrs.exception.IllegalArgumentExceptionMapper;
import org.kiwiproject.jaxrs.exception.IllegalStateExceptionMapper;
import org.kiwiproject.jaxrs.exception.JaxrsExceptionMapper;
import org.kiwiproject.jaxrs.exception.NoSuchElementExceptionMapper;
import org.kiwiproject.jaxrs.exception.WebApplicationExceptionMapper;

import java.lang.invoke.MethodHandle;
Expand Down Expand Up @@ -39,10 +40,11 @@ public static void register(ServerFactory serverFactory, Environment environment
jersey.register(new WebApplicationExceptionMapper());
jersey.register(new IllegalArgumentExceptionMapper());
jersey.register(new IllegalStateExceptionMapper());
jersey.register(new NoSuchElementExceptionMapper());
jersey.register(new JaxrsExceptionMapper());

// Don't allow Dropwizard to register default exception mappers, since we might be overriding the default
// ConstraintViolationExceptionMapper (depending on configuration)
// Don't allow Dropwizard to register default exception mappers, since we are overriding
// its default exception mappers with replacements from kiwi
disableDefaultExceptionMapperRegistration(serverFactory);

// Register replacements for Dropwizard default exception mappers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import io.dropwizard.core.server.DefaultServerFactory;
import io.dropwizard.core.server.ServerFactory;
Expand All @@ -18,6 +19,7 @@
import org.kiwiproject.jaxrs.exception.IllegalArgumentExceptionMapper;
import org.kiwiproject.jaxrs.exception.IllegalStateExceptionMapper;
import org.kiwiproject.jaxrs.exception.JaxrsExceptionMapper;
import org.kiwiproject.jaxrs.exception.NoSuchElementExceptionMapper;
import org.kiwiproject.jaxrs.exception.WebApplicationExceptionMapper;
import org.kiwiproject.test.dropwizard.mockito.DropwizardMockitoMocks;

Expand Down Expand Up @@ -46,6 +48,7 @@ public void setRegisterDefaultExceptionMappers(Boolean registerDefaultExceptionM
verify(jersey).register(isA(WebApplicationExceptionMapper.class));
verify(jersey).register(isA(IllegalArgumentExceptionMapper.class));
verify(jersey).register(isA(IllegalStateExceptionMapper.class));
verify(jersey).register(isA(NoSuchElementExceptionMapper.class));
verify(jersey).register(isA(JaxrsExceptionMapper.class));

verify(jersey).register(any(LoggingExceptionMapper.class));
Expand All @@ -54,6 +57,8 @@ public void setRegisterDefaultExceptionMappers(Boolean registerDefaultExceptionM
verify(jersey).register(isA(EarlyEofExceptionMapper.class));
verify(jersey).register(isA(ConstraintViolationExceptionMapper.class));
verify(jersey).register(isA(JerseyViolationExceptionMapper.class));

verifyNoMoreInteractions(jersey);
}
}

Expand Down

0 comments on commit c92fd74

Please sign in to comment.