Demo: centralized Problem Details error handling
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
one advice class returns 400, 404, 409, 500; prepares JNR-015-LAB1.
Draft outline details
Step by step
- Add the exception hierarchy and make
ProductServicethrowNotFoundException. - Create
ApiExceptionHandlerwith handlers for not found and conflict. - Add a handler for
MethodArgumentNotValidExceptionthat returns field errors in a property. - Planned mistake: a catch-all that returns
ex.getMessage()leaks a database message. Fix: log it, return a generic detail. - Call each case with
curland compare the bodies.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.