nmdp-bioinformatics / service-feature

Enumerated sequence feature service.
GNU Lesser General Public License v3.0
2 stars 10 forks source link

Validation errors should return 400 Bad Request #50

Open heuermh opened 7 years ago

heuermh commented 7 years ago

It appears that UserInputExceptionMapper is registered

$ java -jar target/feature-dropwizard-1.0.6-SNAPSHOT.jar server
INFO  [2017-03-28 23:31:47,071] org.eclipse.jetty.util.log: Logging initialized @808ms
INFO  [2017-03-28 23:31:47,131] io.dropwizard.assets.AssetsBundle: Registering AssetBundle with name: swagger-ui for path /doc/*
Creating new UserInputExceptionMapper
...

but is not used when IllegalArgumentExceptions are thrown

10.11; rv:48.0) Gecko/20100101 Firefox/48.0" 1
ERROR [2017-03-28 23:32:07,960] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: aa2bb2bd17c63194
! java.lang.IllegalArgumentException: sequence must use DNA alphabet [A,C,T,G]
! at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.nmdp.service.feature.service.impl.FeatureServiceImpl.createFeature(FeatureServiceImpl.java:86) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.nmdp.service.feature.resource.FeatureResource.createFeature(FeatureResource.java:125) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
! at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
! at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:164) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:181) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:203) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:101) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:305) ~[feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:401) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:222) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at io.dropwizard.jetty.NonblockingServletHolder.handle(NonblockingServletHolder.java:49) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlets.UserAgentFilter.doFilter(UserAgentFilter.java:83) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:300) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at io.dropwizard.jetty.BiDiGzipFilter.doFilter(BiDiGzipFilter.java:134) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at io.dropwizard.servlets.ThreadNameFilter.doFilter(ThreadNameFilter.java:29) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.handle(AllowedMethodsFilter.java:44) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.doFilter(AllowedMethodsFilter.java:39) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at com.codahale.metrics.jetty9.InstrumentedHandler.handle(InstrumentedHandler.java:240) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at io.dropwizard.jetty.RoutingHandler.handle(RoutingHandler.java:51) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:159) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.Server.handle(Server.java:497) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) [feature-dropwizard-1.0.6-SNAPSHOT.jar:na]
! at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
fscheel commented 7 years ago

I'm currently looking into this as part of the DaSH in Heidelberg but I am very unsure about the best way to solve this.

We caught missing REST parameters in FeatureResource by catching the error and wrapping it with our UserInputException. Which then gets mapped to 400 errors.

Throwing a UserInputException from the library code (FeatureServiceImpl and FeatureServiceJbdi) doesn't sound correct and neither does checking the actual content of the parameters in FeatureResource.

The options I see are the following:

@heuermh Which solution would be your preffered one?