EXCEPTION HANDLING WITH SPRING BOOT
1. Use @ResponseStatus for simple cases
When ResourceNotFoundException get thrown, client will get a 404 status code.
2. Use @ControllerAdvice for Centralized Exception Handling
- @ControllerAdvice handler intercepts exceptions thrown from any controller.
- With ResponseEntity, we can return custom error messages, objects, HTTP status codes and response bodies.
That way, clients that consume our API will have a clear matching between our backend errors and an identifying reason (error code)