The purpose of the blog post is to explain how to do exception handling and data transferring.
Please find the source code for above application. You have to select branch called improved .
This is the improved version of the code explained in previous blog post.
Rest Controller
- Only Rest API related coding included.
- DTO send to service layer
Service Implementation
- Validation happen inside the business logic .
- Exception propagate to controller level.
- DTO used to communicate with web layer.
Controller Advice
- This will capture each exception and send relevant response to client through controller.
Testing
I have used postman to test Rest API.
- You can see that HTTP response code is 204 : No Content
- We are sending timestamp, which is older than 60 seconds time period
- Inside the service layer, we have validated this and throw TimeExceeded Exception.
- According to our controller advice, we should send HTTP response code 204 : No Content
No comments:
Post a Comment