--
You received this message because you are subscribed to the Google Groups "OpenLMIS Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openlmis-dev...@googlegroups.com.
To post to this group, send email to openlm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openlmis-dev/5756FABC.10005%40soldevelo.com.
For more options, visit https://groups.google.com/d/optout.
Hi Sebastian,
I like what you’ve started, and think it relates to a spike (OLMIS-662 - “API Data Validation”) I’ve been working on. What I’ve come up with so far has been committed to the “data-validation-example” branch of the “openlmis-example” repository.
As a team, we’re not yet committed to the validation-related approach illustrated by the aforementioned branch. There’s more exploration to do. As of now, though, I’ve suggested the use of JSR 349 (http://beanvalidation.org/) paired with an occasional JPA annotations. The approach works nicely within the context of Spring Data Rest.
This relates to your spike in that, due to our use of Spring Data Rest, I used the @ControllerAdvice that you mentioned. It works nicely within a Spring Data Rest setup.
A related problem I ran into, though, is that the two kinds of validation (JSR 349 and JPA) yield different response bodies. Spring Boot formats a javax.validation failure-response to look something like this:
{
"timestamp": 1465324940927,
"status": 500,
"error": "Internal Server Error",
"exception": "javax.validation.ConstraintViolationException",
"message": "Validation failed for classes [org.openlmis.example.domain.Bar] during persist time for groups [javax.validation.groups.Default, ]\nList of constraint violations:[\n\tConstraintViolationImpl{interpolatedMessage='must be less than or equal to 500', propertyPath=capacity, rootBeanClass=class org.openlmis.example.domain.Bar, messageTemplate='{javax.validation.constraints.Max.message}'}\n]",
"path": "/api/bars"
}
Simultaneously, a JPA-based validation error might yield:
{
"cause": {
"cause": {
"cause": null,
"message": "ERROR: duplicate key value violates unique constraint \"uk_83gfi2v5x68g22c2j7a5sscee\"\n Detail: Key (name)=(Billy's Place) already exists."
},
"message": "could not execute statement"
},
"message": "could not execute statement; SQL [n/a]; constraint [uk_83gfi2v5x68g22c2j7a5sscee]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"
}
The RestExceptionHandler class in the branch I mentioned is an early attempt to standardize our response bodies. As the “TODO” comment suggests, though, it doesn’t work as intended. While the first "handleConstraintViolationException" defined in the class works properly, the Hibernate-related one seems to be ignored. If you (based on your recent error-handling spike) have any ideas about how to fix this particular @ExceptionHandler, they’d be quite appreciated.
Thank you,
Ben
--
You received this message because you are subscribed to the Google Groups "OpenLMIS Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openlmis-dev...@googlegroups.com.
To post to this group, send email to openlm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openlmis-dev/12bcbdf9-2f8f-4dda-b91c-fcaf90646d77%40googlegroups.com.
Hello everyone.
Darius, error handling methods presented in document attached by Sebastian work well with both Spring Data REST and Spring MVC. I believe there is no other recomended approach designed especially to work with for Spring Data REST. Please do correct me if I am wrong.
Best
Regards,
Weronika