79803420

Date: 2025-10-29 03:57:28
Score: 0.5
Natty:
Report link

The issue is likely that the response status isn't being set properly. Using ResponseEntity (which is the recommended approach in Spring Boot 3.x) gives you explicit control over the HTTP status code.

Change your exception handler to:

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MyBusinessException.class)
    public ResponseEntity<ProblemDetail> handleMyBusinessException(MyBusinessException ex) {
        ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(
            HttpStatus.BAD_REQUEST, 
            ex.getMessage()
        );
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetail);
    }
}

Why this works:

If it still doesn't work, check:

  1. Your @RestControllerAdvice class is in a package scanned by Spring Boot (should be in or under your main application package)

  2. You have the correct imports

import org.springframework.http.HttpStatus;
import org.springframework.http.ProblemDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @ResponseStatus
  • User mentioned (0): @RestControllerAdvice
  • Low reputation (1):
Posted by: Siripireddy Giri