Skip to content
Ameen Abozaid
Planned lessonJNR-015-L06

Demo: centralized Problem Details error handling

  • Lesson 6 of 6
  • Junior
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

  1. Add the exception hierarchy and make ProductService throw NotFoundException.
  2. Create ApiExceptionHandler with handlers for not found and conflict.
  3. Add a handler for MethodArgumentNotValidException that returns field errors in a property.
  4. Planned mistake: a catch-all that returns ex.getMessage() leaks a database message. Fix: log it, return a generic detail.
  5. Call each case with curl and compare the bodies.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.