Open tangobravo62 opened 4 years ago
In some cases input validation results in a status code of 500, which is even worse than 400 without a clarifying message, e. g. the following:
2021-04-22 09:03:57.180 ERROR 1 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.validation.ConstraintViolationException: createOrbits.restOrbit[0].stopTime: must match "^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d{6}$"] with root cause
javax.validation.ConstraintViolationException: createOrbits.restOrbit[0].stopTime: must match "^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d{6}$"
at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:116) ~[spring-context-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at de.dlr.proseo.model.rest.OrbitControllerDecorator$$EnhancerBySpringCGLIB$$794b1d94.createOrbits(<generated>) ~[classes!/:0.7.1]
on an input value of 2020-11-01T16:00:00.xyz
for the orbit stop time.
The standard REST input validation method of Spring only generates an exception, but does not create a meaningful error message for the calling process:
In the CLI this results in the rather terse error message
with "null" being the content of the HTTP "Warning:" header, where an error message would be expected.
A method to intercept Spring's error reporting process and to format a legible error message needs to be found. Look here for a starting point: https://www.baeldung.com/exception-handling-for-rest-with-spring